dsh-yanfield 0.1.11 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +8 -4
- package/README.md +7 -3
- package/dist/client.js +93 -93
- package/dist/host.js +1104 -551
- package/package.json +5 -2
package/dist/host.js
CHANGED
|
@@ -17341,7 +17341,7 @@ var require_turndown_cjs = __commonJS({
|
|
|
17341
17341
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
17342
17342
|
|
|
17343
17343
|
// package.json
|
|
17344
|
-
var version = "0.
|
|
17344
|
+
var version = "0.2.0";
|
|
17345
17345
|
|
|
17346
17346
|
// src/host.ts
|
|
17347
17347
|
import fs2 from "node:fs";
|
|
@@ -17431,6 +17431,19 @@ CREATE TABLE IF NOT EXISTS locations (
|
|
|
17431
17431
|
);
|
|
17432
17432
|
CREATE INDEX IF NOT EXISTS idx_locations_novel ON locations(novel_id);
|
|
17433
17433
|
`;
|
|
17434
|
+
var CHAPTER_VERSION_SCHEMA = `
|
|
17435
|
+
CREATE TABLE IF NOT EXISTS chapter_versions (
|
|
17436
|
+
id TEXT PRIMARY KEY,
|
|
17437
|
+
novel_id TEXT NOT NULL REFERENCES novels(id) ON DELETE CASCADE,
|
|
17438
|
+
chapter_id TEXT NOT NULL REFERENCES chapters(id) ON DELETE CASCADE,
|
|
17439
|
+
chapter_title TEXT NOT NULL,
|
|
17440
|
+
content TEXT NOT NULL,
|
|
17441
|
+
word_count INTEGER NOT NULL,
|
|
17442
|
+
source TEXT NOT NULL CHECK (source IN ('manual', 'before_restore')),
|
|
17443
|
+
created_at TEXT NOT NULL
|
|
17444
|
+
);
|
|
17445
|
+
CREATE INDEX IF NOT EXISTS idx_chapter_versions_chapter ON chapter_versions(chapter_id, created_at DESC);
|
|
17446
|
+
`;
|
|
17434
17447
|
var SCHEMA = `
|
|
17435
17448
|
CREATE TABLE IF NOT EXISTS novels (
|
|
17436
17449
|
id TEXT PRIMARY KEY,
|
|
@@ -17481,6 +17494,8 @@ CREATE TABLE IF NOT EXISTS chapters (
|
|
|
17481
17494
|
CREATE INDEX IF NOT EXISTS idx_chapters_novel ON chapters(novel_id, order_index);
|
|
17482
17495
|
CREATE INDEX IF NOT EXISTS idx_chapters_volume ON chapters(volume_id, order_index);
|
|
17483
17496
|
|
|
17497
|
+
${CHAPTER_VERSION_SCHEMA}
|
|
17498
|
+
|
|
17484
17499
|
CREATE TABLE IF NOT EXISTS novel_outlines (
|
|
17485
17500
|
id TEXT PRIMARY KEY,
|
|
17486
17501
|
novel_id TEXT NOT NULL UNIQUE REFERENCES novels(id) ON DELETE CASCADE,
|
|
@@ -17787,6 +17802,10 @@ var MIGRATIONS = [
|
|
|
17787
17802
|
ids TEXT NOT NULL,
|
|
17788
17803
|
PRIMARY KEY (novel_id, group_key)
|
|
17789
17804
|
)`);
|
|
17805
|
+
},
|
|
17806
|
+
// v7:章节正文版本历史。
|
|
17807
|
+
(db) => {
|
|
17808
|
+
db.exec(CHAPTER_VERSION_SCHEMA);
|
|
17790
17809
|
}
|
|
17791
17810
|
];
|
|
17792
17811
|
var SCHEMA_VERSION = MIGRATIONS.length;
|
|
@@ -19224,6 +19243,7 @@ var library = {
|
|
|
19224
19243
|
|
|
19225
19244
|
// src/yanfield/lib/i18n/en/editor.ts
|
|
19226
19245
|
var editor = {
|
|
19246
|
+
"\u6B64\u5019\u9009\u4F1A\u6574\u4F53\u5E94\u7528\uFF0C\u5305\u542B\u6B63\u6587\u548C\u5176\u4ED6\u7AE0\u8282\u6539\u52A8\u3002": "This applies the whole proposal, including text and other chapter changes.",
|
|
19227
19247
|
"AI \u534F\u4F5C\u9762\u677F": "AI collaboration panel",
|
|
19228
19248
|
"AI \u5FEB\u6377\u4EFB\u52A1": "Quick AI tasks",
|
|
19229
19249
|
"AI \u6B63\u5728\u6309\u672C\u7AE0\u6B63\u6587\u63D0\u53D6\uFF0C\u53EF\u80FD\u9700\u8981\u51E0\u5341\u79D2\u3002": "AI is extracting from this chapter's text. This can take a few dozen seconds.",
|
|
@@ -19248,7 +19268,7 @@ var editor = {
|
|
|
19248
19268
|
"\u5B9A\u4F4D\u6539\u52A8": "Go to change",
|
|
19249
19269
|
"\u4E0A\u4E00\u7AE0": "Previous chapter",
|
|
19250
19270
|
"\u4E0A\u4E00\u7AE0\uFF1A{title}": "Previous chapter: {title}",
|
|
19251
|
-
"\u4E0A\u6B21\u79BB\u5F00\u65F6\u672A\u80FD\u786E\u8BA4\u4FDD\u5B58\u3002\
|
|
19271
|
+
"\u4E0A\u6B21\u79BB\u5F00\u65F6\u672A\u80FD\u786E\u8BA4\u4FDD\u5B58\u3002\u6062\u590D\u8349\u7A3F\u540E\u53EF\u4EE5\u6838\u5BF9\u5185\u5BB9\u3002\u5982\u679C\u5DF2\u4FDD\u5B58\u7248\u672C\u6709\u53D8\u5316\uFF0C\u8BF7\u624B\u52A8\u5408\u5E76\u9700\u8981\u4FDD\u7559\u7684\u5185\u5BB9\u3002\u4E34\u65F6\u8349\u7A3F\u53EA\u4FDD\u5B58\u5728\u6B64\u6D4F\u89C8\u5668\u6807\u7B7E\u9875\u4E2D\u3002": "The last save was not confirmed. Restore the draft to review it. If the saved version changed, merge the text you want to keep manually. The temporary draft is stored in this browser tab.",
|
|
19252
19272
|
"\u4E0A\u79FB": "Move up",
|
|
19253
19273
|
"\u4E0B\u4E00\u4E2A": "Next",
|
|
19254
19274
|
"\u4E0B\u4E00\u4E2A (Enter)": "Next (Enter)",
|
|
@@ -19333,6 +19353,23 @@ var editor = {
|
|
|
19333
19353
|
"\u539F\u6587": "Original",
|
|
19334
19354
|
"\u53D1\u73B0 {n} \u5904\u6863\u6848\u4E0E\u6B63\u6587\u4E0D\u4E00\u81F4\u3002\u82E5\u6863\u6848\u6821\u8BA2\u6B63\u786E\uFF0C\u8BF7\u540C\u6B65\u4FEE\u6539\u6B63\u6587\u3002": { one: "Found {n} place where the archive and the text disagree. If the archive edit is right, update the text to match.", other: "Found {n} places where the archive and the text disagree. If the archive edit is right, update the text to match." },
|
|
19335
19355
|
"\u53D1\u73B0 {n} \u5904\u6863\u6848\u4E0E\u6B63\u6587\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u540C\u6B65\u4FEE\u6539\u6B63\u6587\u3002": { one: "Found {n} place where the archive and the text disagree \u2014 update the text to match.", other: "Found {n} places where the archive and the text disagree \u2014 update the text to match." },
|
|
19356
|
+
"\u7AE0\u8282\u7248\u672C\u5386\u53F2": "Chapter version history",
|
|
19357
|
+
"\u4FDD\u5B58\u5F53\u524D\u6B63\u6587\u7684\u5FEB\u7167\uFF0C\u6216\u9884\u89C8\u5E76\u6062\u590D\u4EE5\u524D\u7684\u6B63\u6587\u3002": "Save a snapshot of the current manuscript, or preview and restore earlier text.",
|
|
19358
|
+
"\u4FDD\u5B58\u7248\u672C\u5FEB\u7167": "Save snapshot",
|
|
19359
|
+
"\u5DF2\u4FDD\u5B58\u7248\u672C\u5FEB\u7167": "Snapshot saved",
|
|
19360
|
+
"\u8FD9\u7AE0\u8FD8\u6CA1\u6709\u7248\u672C\u5FEB\u7167\u3002": "This chapter has no snapshots yet.",
|
|
19361
|
+
"\u5B57\u6570 {count}": "Word count {count}",
|
|
19362
|
+
"\u624B\u52A8\u5FEB\u7167": "Manual snapshot",
|
|
19363
|
+
"\u6062\u590D\u524D\u5FEB\u7167": "Before restore",
|
|
19364
|
+
"\u6B64\u7248\u672C\u6CA1\u6709\u6B63\u6587\u3002": "This version has no manuscript text.",
|
|
19365
|
+
"\u6062\u590D\u8FD9\u4EFD\u6B63\u6587\uFF1F": "Restore this manuscript version?",
|
|
19366
|
+
"\u6062\u590D\u6B64\u7248\u672C": "Restore version",
|
|
19367
|
+
"\u5F53\u524D\u6B63\u6587\u4F1A\u5148\u53E6\u5B58\u4E3A\u5FEB\u7167\uFF0C\u518D\u66FF\u6362\u4E3A\u6240\u9009\u7248\u672C\u7684\u6B63\u6587\u3002": "Your current manuscript will be saved as a snapshot before the selected version replaces it.",
|
|
19368
|
+
"\u5DF2\u6062\u590D\u6B63\u6587\u7248\u672C": "Manuscript version restored",
|
|
19369
|
+
"\u5220\u9664\u8FD9\u4EFD\u7248\u672C\uFF1F": "Delete this snapshot?",
|
|
19370
|
+
"\u5220\u9664\u6B64\u7248\u672C": "Delete snapshot",
|
|
19371
|
+
"\u8FD9\u4EFD\u5FEB\u7167\u5C06\u88AB\u6C38\u4E45\u5220\u9664\u3002": "This snapshot will be permanently deleted.",
|
|
19372
|
+
"\u5DF2\u5220\u9664\u7248\u672C\u5FEB\u7167": "Snapshot deleted",
|
|
19336
19373
|
"\u53D1\u73B0\u672A\u4FDD\u5B58\u7684\u4E34\u65F6\u8349\u7A3F": "Unsaved temporary draft found",
|
|
19337
19374
|
"\u53D6\u6D88": "Cancel",
|
|
19338
19375
|
"\u53EA\u8865\u5145\u4E86\u6B63\u6587\u91CC\u7684\u65B0\u4E8B\u5B9E\u3002\u82E5\u6821\u8BA2\u4E86\u4E8B\u5B9E\uFF0C\u8BF7\u540C\u6B65\u4FEE\u6539\u6B63\u6587\u3002": "Only new facts from the text were added. If you corrected a fact, update the text to match.",
|
|
@@ -19491,7 +19528,7 @@ var editor = {
|
|
|
19491
19528
|
"\u7AE0\u5F85\u63D0\u53D6": { one: "chapter to extract", other: "chapters to extract" },
|
|
19492
19529
|
"\u7AE0\u7EB2": "Outline",
|
|
19493
19530
|
"\u7AE0\u7EB2 \xB7 {ref}": "Chapter outline \xB7 {ref}",
|
|
19494
|
-
"\u7AE0\u8282\u201C{title}\u201D\u7684\u6B63\u6587\
|
|
19531
|
+
"\u7AE0\u8282\u201C{title}\u201D\u7684\u6B63\u6587\u3001\u7AE0\u7EB2\u4E0E\u7248\u672C\u5386\u53F2\u5C06\u4E00\u8D77\u5220\u9664\u3002": "The manuscript, blueprint, and version history for \u201C{title}\u201D will be deleted.",
|
|
19495
19532
|
"\u7AE0\u8282\u52A0\u8F7D\u5931\u8D25\uFF1A{error}": "Failed to load chapters: {error}",
|
|
19496
19533
|
"\u7AE0\u8282\u540D": "Chapter name",
|
|
19497
19534
|
"\u7AE0\u8282\u64CD\u4F5C": "Chapter actions",
|
|
@@ -19974,6 +20011,16 @@ var ai = {
|
|
|
19974
20011
|
"\u5DF2\u6709\u540E\u534A\u7AE0\u7684\u6B63\u6587": "Text in the existing second half",
|
|
19975
20012
|
"\u5E94\u7528\u62C6\u7AE0": "Apply split",
|
|
19976
20013
|
"\u51C6\u5907\u5408\u5E76\u7AE0\u8282": "Prepare chapter merge",
|
|
20014
|
+
"\u51C6\u5907\u6279\u91CF\u6574\u7406\u7AE0\u8282": "Prepare chapter organization",
|
|
20015
|
+
"\u6279\u91CF\u6574\u7406\u7AE0\u8282": "Organize chapters",
|
|
20016
|
+
"\u7AE0\u9996\u8FC7\u6E21\uFF1A{text}": "Opening transition: {text}",
|
|
20017
|
+
"\u7AE0\u5C3E\u8FC7\u6E21\uFF1A{text}": "Closing transition: {text}",
|
|
20018
|
+
"\u6279\u91CF\u6574\u7406\u7AE0\u8282\uFF1A ": "Organize chapters: ",
|
|
20019
|
+
"\u4E00\u6B21\u6574\u7406\u76EE\u5F55\u3001\u6807\u9898\u3001\u6458\u8981\u6216\u5DF2\u62C6\u7AE0\u7684\u91CD\u590D\u7AE0\u5C3E": "Update chapter order, titles, summaries, or duplicate endings from partial splits",
|
|
20020
|
+
"\u67E5\u770B\u76EE\u5F55\u987A\u5E8F": "Review chapter order",
|
|
20021
|
+
"\u539F\u987A\u5E8F": "Previous order",
|
|
20022
|
+
"\u65B0\u987A\u5E8F": "New order",
|
|
20023
|
+
"\u622A\u53BB {count} \u6BB5\u91CD\u590D\u7AE0\u5C3E\uFF0C\u539F\u6587\u5DF2\u4FDD\u7559\u5728\u300C{title}\u300D\u3002": "Remove {count} duplicated paragraphs at the end. The original text is already in \u201C{title}\u201D.",
|
|
19977
20024
|
"\u51C6\u5907\u8DE8\u7AE0\u79FB\u52A8\u6BB5\u843D": "Prepare paragraph move",
|
|
19978
20025
|
"\u5408\u5E76\u7AE0\u8282": "Merge chapters",
|
|
19979
20026
|
"\u5408\u5E76\u7AE0\u8282\uFF1A ": "Merge chapters: ",
|
|
@@ -21331,6 +21378,12 @@ var presets = {
|
|
|
21331
21378
|
|
|
21332
21379
|
// src/yanfield/lib/i18n/en/server.ts
|
|
21333
21380
|
var server = {
|
|
21381
|
+
"\u6BB5\u5185\u4FEE\u6539\u672A\u5339\u914D\uFF0C\u5DF2\u627E\u5230\u53EF\u6838\u5BF9\u7684\u91CD\u590D\u7AE0\u5C3E": "The inline edit did not match. A duplicated chapter ending is available for review.",
|
|
21382
|
+
"\u6BB5\u5185\u4FEE\u6539\u6CA1\u6709\u5339\u914D\u5230\u552F\u4E00\u7684\u539F\u6587": "The inline edit did not match a unique excerpt.",
|
|
21383
|
+
"\u672A\u627E\u5230\u53EF\u5B89\u5168\u622A\u53BB\u7684\u91CD\u590D\u7AE0\u5C3E\uFF0C\u8BF7\u6838\u5BF9\u4E24\u7AE0\u6B63\u6587": "No duplicate ending could be safely removed. Review both chapters.",
|
|
21384
|
+
"\u6BCF\u6B21\u6279\u91CF\u6574\u7406\u53EA\u80FD\u5904\u7406\u540C\u4E00\u5377\u7684\u7AE0\u8282": "Organize chapters from one volume at a time.",
|
|
21385
|
+
"\u4FDD\u7559\u91CD\u590D\u6BB5\u843D\u7684\u7AE0\u8282\u4E0D\u80FD\u540C\u65F6\u622A\u5C3E": "A chapter retaining duplicated paragraphs cannot also be trimmed in the same proposal.",
|
|
21386
|
+
"\u586B\u5199\u7AE0\u8282\u6458\u8981\u524D\u8BF7\u6309 nextOffset \u8BFB\u5B8C\u6574\u7AE0\u6B63\u6587": "Follow nextOffset to read the whole chapter before writing its summary.",
|
|
21334
21387
|
"\u6BB5\u843D\u4F4D\u7F6E\u65E0\u6CD5\u552F\u4E00\u786E\u5B9A\uFF0C\u8BF7\u5F15\u7528\u6BB5\u9996\u539F\u6587": "The paragraph could not be uniquely identified. Quote its opening words.",
|
|
21335
21388
|
"\u6E90\u7AE0\u8282\u6CA1\u6709\u8FD9\u4E48\u591A\u6BB5\u843D": "The source chapter has fewer paragraphs than requested.",
|
|
21336
21389
|
"\u79FB\u52A8\u8303\u56F4\u7684\u7ED3\u675F\u6BB5\u5FC5\u987B\u5728\u8D77\u59CB\u6BB5\u4E4B\u540E": "The ending paragraph must follow the starting paragraph.",
|
|
@@ -21572,6 +21625,10 @@ var server = {
|
|
|
21572
21625
|
"\u8BBE\u5B9A\u6807\u9898\u4E0D\u80FD\u4E3A\u7A7A": "Entry title is required",
|
|
21573
21626
|
"\u8BF7\u4F7F\u7528 multipart/form-data \u4E0A\u4F20 txt \u6587\u4EF6\uFF08\u5B57\u6BB5\u540D file\uFF09": "Upload the txt file as multipart/form-data (field name: file)",
|
|
21574
21627
|
"\u8BF7\u5148\u586B\u5199 API Key\uFF0C\u518D\u62C9\u53D6\u6A21\u578B\u5217\u8868": "Add an API key before fetching the model list",
|
|
21628
|
+
"\u7AE0\u8282\u7248\u672C\u4E0D\u5B58\u5728": "Chapter version not found",
|
|
21629
|
+
"\u7AE0\u8282\u5DF2\u6709\u65B0\u4FEE\u6539\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00\u540E\u518D\u64CD\u4F5C": "This chapter changed elsewhere. Reopen it before continuing.",
|
|
21630
|
+
"expectedUpdatedAt\u4E0D\u80FD\u4E3A\u7A7A": "A chapter revision is required",
|
|
21631
|
+
"\u7AE0\u8282\u5DF2\u6709\u65B0\u4FEE\u6539\u3002\u8BF7\u590D\u5236\u9700\u8981\u4FDD\u7559\u7684\u5185\u5BB9\uFF0C\u518D\u6253\u5F00\u5DF2\u4FDD\u5B58\u7248\u672C\u5408\u5E76\u3002": "This chapter changed elsewhere. Copy the text you want to keep, then open the saved version and merge your changes.",
|
|
21575
21632
|
"\u8D44\u6599\u5DF2\u6709\u65B0\u4FEE\u6539\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00\u5E76\u6838\u5BF9\u540E\u4FDD\u5B58": "This entry changed elsewhere; reopen it, review, and save again",
|
|
21576
21633
|
"\u9884\u8BBE\u4E0D\u5B58\u5728": "Preset not found",
|
|
21577
21634
|
"\u9884\u8BBE\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A": "Preset name is required",
|
|
@@ -21894,7 +21951,7 @@ function norm(v) {
|
|
|
21894
21951
|
if (v !== null && typeof v === "object") return toJson(v);
|
|
21895
21952
|
return v;
|
|
21896
21953
|
}
|
|
21897
|
-
function patch(table, id2, cols, data, jsonKeys = [], hasUpdatedAt = true) {
|
|
21954
|
+
function patch(table, id2, cols, data, jsonKeys = [], hasUpdatedAt = true, updatedAt) {
|
|
21898
21955
|
const sets = [];
|
|
21899
21956
|
const params = [];
|
|
21900
21957
|
for (const [key, col] of Object.entries(cols)) {
|
|
@@ -21906,9 +21963,7 @@ function patch(table, id2, cols, data, jsonKeys = [], hasUpdatedAt = true) {
|
|
|
21906
21963
|
}
|
|
21907
21964
|
if (sets.length === 0) return;
|
|
21908
21965
|
if (hasUpdatedAt) sets.push(`"updated_at" = ?`);
|
|
21909
|
-
params.push(
|
|
21910
|
-
params.pop();
|
|
21911
|
-
if (hasUpdatedAt) params.push(nowIso());
|
|
21966
|
+
if (hasUpdatedAt) params.push(updatedAt ?? nowIso());
|
|
21912
21967
|
run(`UPDATE ${table} SET ${sets.join(", ")} WHERE id = ?`, [...params, id2]);
|
|
21913
21968
|
}
|
|
21914
21969
|
var NOVEL_COLS = {
|
|
@@ -22131,8 +22186,14 @@ function restoreChapter(chapter) {
|
|
|
22131
22186
|
[chapter.id, chapter.novelId, chapter.volumeId, chapter.title, chapter.content, chapter.summary, chapter.status, chapter.orderIndex, chapter.wordCount, chapter.notes, chapter.createdAt, chapter.updatedAt]
|
|
22132
22187
|
);
|
|
22133
22188
|
}
|
|
22189
|
+
function nextChapterStamp(previous) {
|
|
22190
|
+
const previousMs = Date.parse(previous);
|
|
22191
|
+
return Number.isFinite(previousMs) ? new Date(Math.max(Date.now(), previousMs + 1)).toISOString() : nowIso();
|
|
22192
|
+
}
|
|
22134
22193
|
function updateChapter(id2, data) {
|
|
22135
|
-
|
|
22194
|
+
const current = getChapter(id2);
|
|
22195
|
+
if (!current) throw new Error(`chapter not found: ${id2}`);
|
|
22196
|
+
patch("chapters", id2, CHAPTER_COLS, data, [], true, nextChapterStamp(current.updatedAt));
|
|
22136
22197
|
const next = getChapter(id2);
|
|
22137
22198
|
if (!next) throw new Error(`chapter not found: ${id2}`);
|
|
22138
22199
|
return next;
|
|
@@ -22156,7 +22217,7 @@ function moveChapter(id2, target2) {
|
|
|
22156
22217
|
const index = target2.orderIndex === void 0 ? siblings.length : Math.max(0, Math.min(target2.orderIndex, siblings.length));
|
|
22157
22218
|
siblings.splice(index, 0, id2);
|
|
22158
22219
|
tx(() => {
|
|
22159
|
-
run("UPDATE chapters SET updated_at = ? WHERE id = ?", [
|
|
22220
|
+
run("UPDATE chapters SET updated_at = ? WHERE id = ?", [nextChapterStamp(current.updatedAt), id2]);
|
|
22160
22221
|
setChapterPositions(current.novelId, siblings.map((cid, orderIndex) => ({ id: cid, volumeId, orderIndex })));
|
|
22161
22222
|
});
|
|
22162
22223
|
return updateChapter(id2, {});
|
|
@@ -43541,6 +43602,73 @@ function agentLinkKey(kind, id2) {
|
|
|
43541
43602
|
return `${kind}:${id2}`;
|
|
43542
43603
|
}
|
|
43543
43604
|
|
|
43605
|
+
// src/yanfield/lib/db/chapter-versions.ts
|
|
43606
|
+
var summary = "id, chapter_title AS chapterTitle, word_count AS wordCount, source, created_at AS createdAt";
|
|
43607
|
+
function requireChapter(chapterId) {
|
|
43608
|
+
const chapter = getChapter(chapterId);
|
|
43609
|
+
if (!chapter) throw new ApiError("\u7AE0\u8282\u4E0D\u5B58\u5728", 404);
|
|
43610
|
+
return chapter;
|
|
43611
|
+
}
|
|
43612
|
+
function requireCurrentChapter(chapterId, expectedUpdatedAt) {
|
|
43613
|
+
const chapter = requireChapter(chapterId);
|
|
43614
|
+
if (chapter.updatedAt !== expectedUpdatedAt) {
|
|
43615
|
+
throw new ApiError("\u7AE0\u8282\u5DF2\u6709\u65B0\u4FEE\u6539\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00\u540E\u518D\u64CD\u4F5C", 409);
|
|
43616
|
+
}
|
|
43617
|
+
return chapter;
|
|
43618
|
+
}
|
|
43619
|
+
function hasChapterVersions(chapterId) {
|
|
43620
|
+
return Boolean(get("SELECT 1 FROM chapter_versions WHERE chapter_id = ? LIMIT 1", [chapterId]));
|
|
43621
|
+
}
|
|
43622
|
+
function listChapterVersions(chapterId) {
|
|
43623
|
+
requireChapter(chapterId);
|
|
43624
|
+
return all(
|
|
43625
|
+
`SELECT ${summary} FROM chapter_versions WHERE chapter_id = ? ORDER BY created_at DESC, rowid DESC`,
|
|
43626
|
+
[chapterId]
|
|
43627
|
+
);
|
|
43628
|
+
}
|
|
43629
|
+
function getChapterVersion(chapterId, versionId) {
|
|
43630
|
+
const version3 = get(
|
|
43631
|
+
`SELECT ${summary}, content FROM chapter_versions WHERE chapter_id = ? AND id = ?`,
|
|
43632
|
+
[chapterId, versionId]
|
|
43633
|
+
);
|
|
43634
|
+
if (!version3) throw new ApiError("\u7AE0\u8282\u7248\u672C\u4E0D\u5B58\u5728", 404);
|
|
43635
|
+
return version3;
|
|
43636
|
+
}
|
|
43637
|
+
function insertVersion(chapter, source) {
|
|
43638
|
+
const version3 = {
|
|
43639
|
+
id: uid("version"),
|
|
43640
|
+
chapterTitle: chapter.title,
|
|
43641
|
+
wordCount: chapter.wordCount,
|
|
43642
|
+
source,
|
|
43643
|
+
createdAt: nowIso()
|
|
43644
|
+
};
|
|
43645
|
+
run(
|
|
43646
|
+
`INSERT INTO chapter_versions (id, novel_id, chapter_id, chapter_title, content, word_count, source, created_at)
|
|
43647
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
43648
|
+
[version3.id, chapter.novelId, chapter.id, version3.chapterTitle, chapter.content, version3.wordCount, source, version3.createdAt]
|
|
43649
|
+
);
|
|
43650
|
+
return version3;
|
|
43651
|
+
}
|
|
43652
|
+
function createChapterVersion(chapterId, expectedUpdatedAt) {
|
|
43653
|
+
return tx(() => insertVersion(requireCurrentChapter(chapterId, expectedUpdatedAt), "manual"));
|
|
43654
|
+
}
|
|
43655
|
+
function restoreChapterVersion(chapterId, versionId, expectedUpdatedAt) {
|
|
43656
|
+
return tx(() => {
|
|
43657
|
+
const chapter = requireCurrentChapter(chapterId, expectedUpdatedAt);
|
|
43658
|
+
const version3 = getChapterVersion(chapterId, versionId);
|
|
43659
|
+
if (chapter.content === version3.content) return chapter;
|
|
43660
|
+
insertVersion(chapter, "before_restore");
|
|
43661
|
+
const restored = updateChapter(chapterId, { content: version3.content, wordCount: countWords(version3.content) });
|
|
43662
|
+
markArchiveStale(chapterId);
|
|
43663
|
+
markArchivesStaleAfter(chapter.novelId, -1);
|
|
43664
|
+
return restored;
|
|
43665
|
+
});
|
|
43666
|
+
}
|
|
43667
|
+
function deleteChapterVersion(chapterId, versionId) {
|
|
43668
|
+
const result = run("DELETE FROM chapter_versions WHERE chapter_id = ? AND id = ?", [chapterId, versionId]);
|
|
43669
|
+
if (!result.changes) throw new ApiError("\u7AE0\u8282\u7248\u672C\u4E0D\u5B58\u5728", 404);
|
|
43670
|
+
}
|
|
43671
|
+
|
|
43544
43672
|
// src/yanfield/lib/ai/agent/chapter-directory.ts
|
|
43545
43673
|
function chapterPositions(novelId, volumes) {
|
|
43546
43674
|
return listChapters(novelId, false).filter((chapter) => volumes.has(chapter.volumeId)).map(({ id: id2, volumeId, orderIndex }) => ({ id: id2, volumeId, orderIndex }));
|
|
@@ -43552,6 +43680,7 @@ function assertChapterTitle(novelId, volumeId, title, exceptId) {
|
|
|
43552
43680
|
}
|
|
43553
43681
|
function chapterDependencies(id2) {
|
|
43554
43682
|
const labels2 = [];
|
|
43683
|
+
if (hasChapterVersions(id2)) labels2.push("\u7AE0\u8282\u7248\u672C\u5386\u53F2");
|
|
43555
43684
|
if (get("SELECT id FROM chapter_blueprints WHERE chapter_id = ?", [id2])) labels2.push("\u7AE0\u7EB2");
|
|
43556
43685
|
if (getArchiveByChapter(id2)) labels2.push("\u6545\u4E8B\u6863\u6848");
|
|
43557
43686
|
if (get("SELECT id FROM foreshadows WHERE planted_chapter_id = ? OR payoff_chapter_id = ?", [id2, id2])) labels2.push("\u4F0F\u7B14");
|
|
@@ -43561,13 +43690,13 @@ function chapterDependencies(id2) {
|
|
|
43561
43690
|
function reindexChapters(novelId, positions) {
|
|
43562
43691
|
setChapterPositions(novelId, positions.map((entry, orderIndex) => ({ ...entry, orderIndex })));
|
|
43563
43692
|
}
|
|
43564
|
-
function hasChapterConflict(run2, ids, volumes) {
|
|
43693
|
+
function hasChapterConflict(run2, ids, volumes, except = []) {
|
|
43565
43694
|
return run2.changes.some((change) => {
|
|
43566
|
-
if (change.state !== "pending" || change.kind !== "chapter") return false;
|
|
43695
|
+
if (except.includes(change) || change.state !== "pending" || change.kind !== "chapter") return false;
|
|
43567
43696
|
const action = change.chapterDirectory;
|
|
43568
|
-
const order = change.chapterSplit?.orderBefore ?? (change.chapterPair?.kind === "merge" ? change.chapterPair.orderBefore : void 0) ?? (action && "orderBefore" in action ? action.orderBefore : []);
|
|
43697
|
+
const order = change.chapterBatch?.orderBefore ?? change.chapterSplit?.orderBefore ?? (change.chapterPair?.kind === "merge" ? change.chapterPair.orderBefore : void 0) ?? (action && "orderBefore" in action ? action.orderBefore : []);
|
|
43569
43698
|
const linkedId = change.chapterSplit?.existing?.id ?? change.chapterPair?.second.id ?? (action?.kind === "move" ? action.anchorId : void 0);
|
|
43570
|
-
return change.targetId !== null && ids.includes(change.targetId) || linkedId !== void 0 && ids.includes(linkedId) || order.some((entry) => volumes.has(entry.volumeId));
|
|
43699
|
+
return change.targetId !== null && ids.includes(change.targetId) || linkedId !== void 0 && ids.includes(linkedId) || Boolean(change.chapterBatch?.entries.some((entry) => ids.includes(entry.before.id) || Boolean(entry.duplicateIn && ids.includes(entry.duplicateIn.id)))) || order.some((entry) => volumes.has(entry.volumeId));
|
|
43571
43700
|
});
|
|
43572
43701
|
}
|
|
43573
43702
|
function readSavedChapter(run2, id2, observed) {
|
|
@@ -43938,6 +44067,320 @@ function undoChapterPair(run2, change) {
|
|
|
43938
44067
|
change.state = "reverted";
|
|
43939
44068
|
}
|
|
43940
44069
|
|
|
44070
|
+
// src/yanfield/lib/ai/agent/prose-edit.ts
|
|
44071
|
+
function escapeProse(text3) {
|
|
44072
|
+
return text3.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
44073
|
+
}
|
|
44074
|
+
function writerPlainText(output2) {
|
|
44075
|
+
const text3 = output2.trim().replace(/^```(?:html|text)?\s*\n([\s\S]*?)\n```$/i, "$1").trim();
|
|
44076
|
+
return /^<p(?:\s[^>]*)?>[\s\S]*<\/p>$/i.test(text3) ? stripHtml(text3) : text3;
|
|
44077
|
+
}
|
|
44078
|
+
function prepareProseEdit(html, original, range) {
|
|
44079
|
+
const offsets = [];
|
|
44080
|
+
let text3 = "";
|
|
44081
|
+
let seenBlock = false;
|
|
44082
|
+
const add = (value, from, to) => {
|
|
44083
|
+
text3 += value;
|
|
44084
|
+
for (let i = 0; i < value.length; i++) offsets.push({ from, to });
|
|
44085
|
+
};
|
|
44086
|
+
for (const token of html.matchAll(/<[^>]*>|&(?:#\d+|#x[\da-f]+|[a-z][a-z\d]*);|[^<&]+|[<&]/gi)) {
|
|
44087
|
+
const [value] = token;
|
|
44088
|
+
const from = token.index;
|
|
44089
|
+
if (/^<(p|h[1-6]|pre)(?:\s|>)/i.test(value)) {
|
|
44090
|
+
if (seenBlock) add("\n", from, from);
|
|
44091
|
+
seenBlock = true;
|
|
44092
|
+
} else if (/^<br\b/i.test(value)) {
|
|
44093
|
+
add("\n", from, from + value.length);
|
|
44094
|
+
} else if (!/^<[^>]*>$/.test(value)) {
|
|
44095
|
+
const decoded = value.startsWith("&") ? stripHtml(value) || (value === " " || value === " " ? " " : value) : value;
|
|
44096
|
+
if (decoded !== value) add(decoded, from, from + value.length);
|
|
44097
|
+
else for (let i = 0; i < value.length; i++) add(value[i], from + i, from + i + 1);
|
|
44098
|
+
}
|
|
44099
|
+
}
|
|
44100
|
+
const start = range?.from ?? text3.indexOf(original);
|
|
44101
|
+
if (start < 0 || text3.slice(start, range?.to ?? start + original.length) !== original || !range && text3.indexOf(original, start + 1) !== -1) {
|
|
44102
|
+
throw new Error("\u9009\u533A\u5DF2\u53D8\u5316\u6216\u65E0\u6CD5\u5B9A\u4F4D\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u6B63\u6587");
|
|
44103
|
+
}
|
|
44104
|
+
let position = start;
|
|
44105
|
+
const fragments = original.split("\n").flatMap((line, index) => {
|
|
44106
|
+
const spans = offsets.slice(position, position + line.length);
|
|
44107
|
+
position += line.length + 1;
|
|
44108
|
+
return line.trim() ? [{ id: index + 1, text: line, spans }] : [];
|
|
44109
|
+
});
|
|
44110
|
+
return {
|
|
44111
|
+
fragments: fragments.map(({ id: id2, text: text4 }) => ({ id: id2, text: text4 })),
|
|
44112
|
+
patches: (replacement) => fragments.flatMap(({ id: id2, text: line, spans }) => {
|
|
44113
|
+
const value = replacement.get(id2);
|
|
44114
|
+
if (value === void 0) return [];
|
|
44115
|
+
const revised = value.trim() ? line.slice(0, line.length - line.trimStart().length) + value.trim() + line.slice(line.trimEnd().length) : "";
|
|
44116
|
+
if (line === revised) return [];
|
|
44117
|
+
let prefix2 = 0;
|
|
44118
|
+
while (prefix2 < line.length && line[prefix2] === revised[prefix2]) prefix2++;
|
|
44119
|
+
let suffix = 0;
|
|
44120
|
+
while (suffix < line.length - prefix2 && suffix < revised.length - prefix2 && line[line.length - 1 - suffix] === revised[revised.length - 1 - suffix]) suffix++;
|
|
44121
|
+
const middle = spans.slice(prefix2, line.length - suffix);
|
|
44122
|
+
const inserted = escapeProse(revised.slice(prefix2, revised.length - suffix));
|
|
44123
|
+
if (!middle.length) {
|
|
44124
|
+
const at = spans[prefix2]?.from ?? spans.at(-1).to;
|
|
44125
|
+
return [{ from: at, to: at, value: inserted }];
|
|
44126
|
+
}
|
|
44127
|
+
return middle.map((span, i) => ({ ...span, value: i === 0 ? inserted : "" }));
|
|
44128
|
+
})
|
|
44129
|
+
};
|
|
44130
|
+
}
|
|
44131
|
+
function applyProsePatches(html, patches) {
|
|
44132
|
+
let end = html.length;
|
|
44133
|
+
for (const patch3 of patches.sort((a, b2) => b2.from - a.from)) {
|
|
44134
|
+
if (patch3.to > end || patch3.from === end && patch3.from === patch3.to) {
|
|
44135
|
+
throw new Error("\u5C40\u90E8\u4FEE\u6539\u8303\u56F4\u91CD\u53E0\uFF0C\u8BF7\u5408\u5E76\u540E\u91CD\u8BD5");
|
|
44136
|
+
}
|
|
44137
|
+
html = html.slice(0, patch3.from) + patch3.value + html.slice(patch3.to);
|
|
44138
|
+
end = patch3.from;
|
|
44139
|
+
}
|
|
44140
|
+
return html;
|
|
44141
|
+
}
|
|
44142
|
+
function editProse(html, edits) {
|
|
44143
|
+
const patches = edits.flatMap((edit) => {
|
|
44144
|
+
if (/[\r\n\u2028\u2029]/.test(edit.original) || /[\r\n\u2028\u2029]/.test(edit.replacement)) {
|
|
44145
|
+
throw new Error("\u4FEE\u8BA2\u672A\u80FD\u4FDD\u7559\u539F\u6765\u7684\u6BB5\u843D\u7ED3\u6784\uFF0C\u8BF7\u91CD\u8BD5\u6216\u7F29\u5C0F\u9009\u533A");
|
|
44146
|
+
}
|
|
44147
|
+
return prepareProseEdit(html, edit.original).patches(/* @__PURE__ */ new Map([[1, edit.replacement]]));
|
|
44148
|
+
});
|
|
44149
|
+
return applyProsePatches(html, patches);
|
|
44150
|
+
}
|
|
44151
|
+
|
|
44152
|
+
// src/yanfield/lib/ai/agent/types.ts
|
|
44153
|
+
function isChapterOperation(change) {
|
|
44154
|
+
return Boolean(change.chapterSplit || change.chapterDirectory || change.chapterPair || change.chapterBatch);
|
|
44155
|
+
}
|
|
44156
|
+
var ENTITY_LABEL = {
|
|
44157
|
+
chapter: "\u6B63\u6587",
|
|
44158
|
+
blueprint: "\u7AE0\u7EB2",
|
|
44159
|
+
character: "\u89D2\u8272",
|
|
44160
|
+
world: "\u8BBE\u5B9A",
|
|
44161
|
+
location: "\u5730\u70B9",
|
|
44162
|
+
foreshadow: "\u4F0F\u7B14",
|
|
44163
|
+
outline: "\u603B\u7EB2",
|
|
44164
|
+
"volume-outline": "\u5377\u7EB2"
|
|
44165
|
+
};
|
|
44166
|
+
|
|
44167
|
+
// src/yanfield/lib/ai/agent/chapter-batch.ts
|
|
44168
|
+
function findDuplicatedSuffix(content, counterpart) {
|
|
44169
|
+
const meaningful = (blocks) => blocks.filter((block) => !/^<p>\s*(?:<br\s*\/?>\s*)?<\/p>$/i.test(block.html.trim()));
|
|
44170
|
+
const source = splitBlocks(content);
|
|
44171
|
+
const required2 = meaningful(source);
|
|
44172
|
+
const existing = meaningful(splitBlocks(counterpart));
|
|
44173
|
+
let index = required2.length - 1;
|
|
44174
|
+
for (let j = existing.length - 1; j >= 0 && index >= 0; j--) {
|
|
44175
|
+
if (existing[j].html.trim() === required2[index].html.trim()) index--;
|
|
44176
|
+
}
|
|
44177
|
+
const count = required2.length - index - 1;
|
|
44178
|
+
if (count < 2 || index < 0) return null;
|
|
44179
|
+
const lastKept = required2[index];
|
|
44180
|
+
let offset = 0;
|
|
44181
|
+
for (const block of source) {
|
|
44182
|
+
offset = content.indexOf(block.html, offset) + block.html.length;
|
|
44183
|
+
if (block === lastKept) break;
|
|
44184
|
+
}
|
|
44185
|
+
return { content: content.slice(0, offset), count };
|
|
44186
|
+
}
|
|
44187
|
+
function suggestChapterTailRepair(novelId, id2) {
|
|
44188
|
+
const source = getChapter(id2);
|
|
44189
|
+
if (source?.novelId !== novelId) return void 0;
|
|
44190
|
+
const siblings = listChapters(novelId, false).filter((chapter) => chapter.volumeId === source.volumeId);
|
|
44191
|
+
const index = siblings.findIndex((chapter) => chapter.id === id2);
|
|
44192
|
+
const subsequent = siblings.slice(index + 1, index + 4);
|
|
44193
|
+
const matches = subsequent.flatMap((chapter) => {
|
|
44194
|
+
const full = getChapter(chapter.id);
|
|
44195
|
+
const suffix = full && findDuplicatedSuffix(source.content, full.content);
|
|
44196
|
+
return suffix ? [{
|
|
44197
|
+
duplicateTailIn: chapter.id,
|
|
44198
|
+
title: chapter.title,
|
|
44199
|
+
paragraphs: suffix.count,
|
|
44200
|
+
removedText: source.content.slice(suffix.content.length)
|
|
44201
|
+
}] : [];
|
|
44202
|
+
}).sort((a, b2) => b2.paragraphs - a.paragraphs);
|
|
44203
|
+
return matches[0] && matches[0].paragraphs !== matches[1]?.paragraphs ? matches[0] : void 0;
|
|
44204
|
+
}
|
|
44205
|
+
function stageChapterBatch(run2, input2, observed, chapterPages) {
|
|
44206
|
+
const ids = /* @__PURE__ */ new Set([
|
|
44207
|
+
...input2.changes.flatMap((item) => item.duplicateTailIn ? [item.id, item.duplicateTailIn] : [item.id]),
|
|
44208
|
+
...input2.moves.flatMap((item) => [item.id, item.anchorId])
|
|
44209
|
+
]);
|
|
44210
|
+
if (!ids.size) throw new ApiError("\u5185\u5BB9\u6CA1\u6709\u53D8\u5316", 400);
|
|
44211
|
+
const chapters = new Map([...ids].map((id2) => {
|
|
44212
|
+
const chapter = observed.has(`chapter:${id2}`) ? readSavedChapter(run2, id2, observed) : getChapter(id2);
|
|
44213
|
+
if (chapter?.novelId !== run2.novelId) throw new ApiError("\u7AE0\u8282\u4E0D\u5C5E\u4E8E\u8BE5\u4F5C\u54C1", 400);
|
|
44214
|
+
return [id2, chapter];
|
|
44215
|
+
}));
|
|
44216
|
+
const first = chapters.values().next().value;
|
|
44217
|
+
const volumeId = first.volumeId;
|
|
44218
|
+
if ([...chapters.values()].some((chapter) => chapter.volumeId !== volumeId)) {
|
|
44219
|
+
throw new ApiError("\u6BCF\u6B21\u6279\u91CF\u6574\u7406\u53EA\u80FD\u5904\u7406\u540C\u4E00\u5377\u7684\u7AE0\u8282", 400);
|
|
44220
|
+
}
|
|
44221
|
+
const volumes = /* @__PURE__ */ new Set([volumeId]);
|
|
44222
|
+
const existing = run2.changes.find((change2) => change2.state === "pending" && change2.chapterBatch?.volumeId === volumeId);
|
|
44223
|
+
const absorbed = run2.changes.filter((change2) => change2.kind === "chapter" && change2.state === "pending" && !change2.op && !isChapterOperation(change2) && change2.targetId && ids.has(change2.targetId) && typeof change2.after.content === "string" && Object.keys(change2.after).length === 1 && !run2.changes.some((other) => other.state === "pending" && (other.targetId === change2.id || other.evidence?.some((evidence2) => evidence2.candidate && evidence2.sourceId === change2.id))));
|
|
44224
|
+
if (hasChapterConflict(run2, [...ids], volumes, existing ? [existing, ...absorbed] : absorbed)) {
|
|
44225
|
+
throw new ApiError("\u8FD9\u4E9B\u7AE0\u8282\u5DF2\u6709\u5F85\u5BA1\u6539\u52A8\uFF0C\u8BF7\u5148\u5904\u7406\u540E\u518D\u7EE7\u7EED", 409);
|
|
44226
|
+
}
|
|
44227
|
+
if (new Set(input2.changes.map((item) => item.id)).size !== input2.changes.length || new Set(input2.moves.map((item) => item.id)).size !== input2.moves.length) {
|
|
44228
|
+
throw new ApiError("\u6539\u52A8\u91CD\u590D", 400);
|
|
44229
|
+
}
|
|
44230
|
+
const previous = existing?.chapterBatch;
|
|
44231
|
+
const orderBefore = chapterPositions(run2.novelId, volumes);
|
|
44232
|
+
const titles = savedTitles(run2, volumeId);
|
|
44233
|
+
if (previous && (!sameFields(orderBefore, previous.orderBefore) || !sameFields(titles, previous.titles))) {
|
|
44234
|
+
throw new ApiError("\u76EE\u5F55\u5728\u5019\u9009\u751F\u6210\u540E\u53D1\u751F\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u51C6\u5907\u5019\u9009", 409);
|
|
44235
|
+
}
|
|
44236
|
+
const staged = new Map((previous?.entries ?? []).map((entry) => [entry.before.id, structuredClone(entry)]));
|
|
44237
|
+
for (const draft of absorbed) {
|
|
44238
|
+
const before = chapters.get(draft.targetId);
|
|
44239
|
+
if (!sameFields(draft.before, before) || staged.has(before.id)) {
|
|
44240
|
+
throw new ApiError("\u7AE0\u8282\u5728\u5019\u9009\u751F\u6210\u540E\u53D1\u751F\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u51C6\u5907\u5019\u9009", 409);
|
|
44241
|
+
}
|
|
44242
|
+
const content = String(draft.after.content);
|
|
44243
|
+
staged.set(before.id, { before, after: { content }, proseBase: content });
|
|
44244
|
+
}
|
|
44245
|
+
for (const item of input2.changes) {
|
|
44246
|
+
const before = chapters.get(item.id);
|
|
44247
|
+
const entry = staged.get(item.id) ?? { before, after: {} };
|
|
44248
|
+
if (!sameFields(before, entry.before)) throw new ApiError("\u7AE0\u8282\u5728\u5019\u9009\u751F\u6210\u540E\u53D1\u751F\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u51C6\u5907\u5019\u9009", 409);
|
|
44249
|
+
const after = entry.after;
|
|
44250
|
+
const base2 = entry.proseBase ?? before.content;
|
|
44251
|
+
if (item.title !== void 0) {
|
|
44252
|
+
if (item.title === before.title) delete after.title;
|
|
44253
|
+
else after.title = item.title;
|
|
44254
|
+
}
|
|
44255
|
+
if (item.summary !== void 0) {
|
|
44256
|
+
if (item.summary === before.summary) delete after.summary;
|
|
44257
|
+
else {
|
|
44258
|
+
if (item.summary && (chapterPages.get(item.id) ?? 0) < (after.content ?? before.content).length) {
|
|
44259
|
+
throw new ApiError("\u586B\u5199\u7AE0\u8282\u6458\u8981\u524D\u8BF7\u6309 nextOffset \u8BFB\u5B8C\u6574\u7AE0\u6B63\u6587", 400);
|
|
44260
|
+
}
|
|
44261
|
+
after.summary = item.summary;
|
|
44262
|
+
}
|
|
44263
|
+
}
|
|
44264
|
+
if (item.duplicateTailIn) {
|
|
44265
|
+
if (item.duplicateTailIn === item.id) throw new ApiError("\u8BF7\u9009\u62E9\u4E24\u4E2A\u4E0D\u540C\u7684\u7AE0\u8282", 400);
|
|
44266
|
+
const duplicateIn = chapters.get(item.duplicateTailIn);
|
|
44267
|
+
const retainedCopy = staged.get(duplicateIn.id)?.after.content ?? duplicateIn.content;
|
|
44268
|
+
const trimmed = findDuplicatedSuffix(base2, retainedCopy);
|
|
44269
|
+
if (!trimmed) throw new ApiError("\u672A\u627E\u5230\u53EF\u5B89\u5168\u622A\u53BB\u7684\u91CD\u590D\u7AE0\u5C3E\uFF0C\u8BF7\u6838\u5BF9\u4E24\u7AE0\u6B63\u6587", 409);
|
|
44270
|
+
entry.duplicateIn = duplicateIn;
|
|
44271
|
+
entry.removedBlocks = trimmed.count;
|
|
44272
|
+
entry.removedText = base2.slice(trimmed.content.length);
|
|
44273
|
+
}
|
|
44274
|
+
if (item.transition) {
|
|
44275
|
+
const { edge, text: text3 } = item.transition;
|
|
44276
|
+
entry.transitions = { ...entry.transitions, [edge]: text3 };
|
|
44277
|
+
}
|
|
44278
|
+
if (item.duplicateTailIn || item.transition || item.inlineEdits) {
|
|
44279
|
+
const removed = entry.removedText ?? (entry.duplicateIn ? base2.slice(after.content?.length) : "");
|
|
44280
|
+
let retained = base2.slice(0, base2.length - removed.length);
|
|
44281
|
+
if (item.inlineEdits) {
|
|
44282
|
+
retained = editProse(retained, item.inlineEdits);
|
|
44283
|
+
entry.proseBase = retained + removed;
|
|
44284
|
+
}
|
|
44285
|
+
after.content = proseParagraph(entry.transitions?.start) + retained + proseParagraph(entry.transitions?.end);
|
|
44286
|
+
}
|
|
44287
|
+
if (Object.keys(after).length) staged.set(item.id, entry);
|
|
44288
|
+
else staged.delete(item.id);
|
|
44289
|
+
}
|
|
44290
|
+
const entries = [...staged.values()];
|
|
44291
|
+
const repairing = new Set(entries.filter((entry) => entry.duplicateIn).map((entry) => entry.before.id));
|
|
44292
|
+
if (entries.some((entry) => entry.duplicateIn && repairing.has(entry.duplicateIn.id))) {
|
|
44293
|
+
throw new ApiError("\u4FDD\u7559\u91CD\u590D\u6BB5\u843D\u7684\u7AE0\u8282\u4E0D\u80FD\u540C\u65F6\u622A\u5C3E", 409);
|
|
44294
|
+
}
|
|
44295
|
+
for (const entry of entries) {
|
|
44296
|
+
const counterpart = entry.duplicateIn && staged.get(entry.duplicateIn.id);
|
|
44297
|
+
if (counterpart?.after.content !== void 0 && (findDuplicatedSuffix(entry.proseBase ?? entry.before.content, counterpart.after.content)?.count ?? 0) < (entry.removedBlocks ?? 0)) {
|
|
44298
|
+
throw new ApiError("\u5DF2\u6709\u7AE0\u8282\u672A\u5305\u542B\u5B8C\u6574\u7684\u5F85\u79FB\u6B63\u6587\uFF0C\u8BF7\u6838\u5BF9\u540E\u518D\u62C6\u7AE0", 409);
|
|
44299
|
+
}
|
|
44300
|
+
}
|
|
44301
|
+
const arranged = [...previous?.orderAfter ?? orderBefore];
|
|
44302
|
+
for (const move of input2.moves) {
|
|
44303
|
+
if (move.id === move.anchorId) throw new ApiError("\u8BF7\u9009\u62E9\u53E6\u4E00\u7AE0\u4F5C\u4E3A\u79FB\u52A8\u4F4D\u7F6E", 400);
|
|
44304
|
+
const [item] = arranged.splice(arranged.findIndex((entry) => entry.id === move.id), 1);
|
|
44305
|
+
const index = arranged.findIndex((entry) => entry.id === move.anchorId);
|
|
44306
|
+
arranged.splice(index + Number(move.placement === "after"), 0, item);
|
|
44307
|
+
}
|
|
44308
|
+
const changedOrder = arranged.some((entry, index) => entry.id !== orderBefore[index].id);
|
|
44309
|
+
const orderAfter = changedOrder ? arranged.map((entry, orderIndex) => ({ ...entry, orderIndex })) : orderBefore;
|
|
44310
|
+
if (!changedOrder && !entries.length) throw new ApiError("\u5185\u5BB9\u6CA1\u6709\u53D8\u5316", 400);
|
|
44311
|
+
const changedTitles = new Map(entries.filter((entry) => entry.after.title !== void 0).map((entry) => [entry.before.id, entry.after.title]));
|
|
44312
|
+
assertTitles(titles, changedTitles);
|
|
44313
|
+
const chapterBatch = { volumeId, orderBefore, orderAfter, entries, titles };
|
|
44314
|
+
const change = existing ?? {
|
|
44315
|
+
id: uid("change"),
|
|
44316
|
+
kind: "chapter",
|
|
44317
|
+
targetId: first.id,
|
|
44318
|
+
title: first.title,
|
|
44319
|
+
before: { ...first },
|
|
44320
|
+
after: {},
|
|
44321
|
+
reason: input2.reason,
|
|
44322
|
+
state: "pending"
|
|
44323
|
+
};
|
|
44324
|
+
change.chapterBatch = chapterBatch;
|
|
44325
|
+
for (const draft of absorbed) draft.state = "rejected";
|
|
44326
|
+
const absorbedIds = new Set(absorbed.map((draft) => draft.id));
|
|
44327
|
+
for (const step of run2.steps) {
|
|
44328
|
+
for (const target2 of step.targets ?? []) {
|
|
44329
|
+
if (target2.changeId && absorbedIds.has(target2.changeId)) target2.changeId = change.id;
|
|
44330
|
+
}
|
|
44331
|
+
}
|
|
44332
|
+
if (!existing) run2.changes.push(change);
|
|
44333
|
+
return change;
|
|
44334
|
+
}
|
|
44335
|
+
function proseParagraph(text3) {
|
|
44336
|
+
return text3 ? "<p>" + escapeProse(text3.replace(/\s*\n\s*/g, " ")) + "</p>" : "";
|
|
44337
|
+
}
|
|
44338
|
+
function assertTitles(titles, replacements) {
|
|
44339
|
+
for (const [id2, title] of replacements) {
|
|
44340
|
+
if (Object.entries(titles).some(([other, current]) => other !== id2 && (replacements.get(other) ?? current) === title)) {
|
|
44341
|
+
throw new ApiError("\u7AE0\u8282\u6807\u9898\u6216\u5E8F\u53F7\u5DF2\u88AB\u5360\u7528", 409);
|
|
44342
|
+
}
|
|
44343
|
+
}
|
|
44344
|
+
}
|
|
44345
|
+
function savedTitles(run2, volumeId) {
|
|
44346
|
+
return Object.fromEntries(listChapters(run2.novelId, false).filter((chapter) => chapter.volumeId === volumeId).map((chapter) => [chapter.id, chapter.title]));
|
|
44347
|
+
}
|
|
44348
|
+
function applyChapterBatch(run2, change) {
|
|
44349
|
+
const batch = change.chapterBatch;
|
|
44350
|
+
if (!sameFields(chapterPositions(run2.novelId, /* @__PURE__ */ new Set([batch.volumeId])), batch.orderBefore) || !sameFields(savedTitles(run2, batch.volumeId), batch.titles)) {
|
|
44351
|
+
throw new ApiError("\u76EE\u5F55\u5728\u5019\u9009\u751F\u6210\u540E\u53D1\u751F\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u51C6\u5907\u5019\u9009", 409);
|
|
44352
|
+
}
|
|
44353
|
+
for (const { before, duplicateIn } of batch.entries) {
|
|
44354
|
+
if (before.novelId !== run2.novelId || !sameFields(getChapter(before.id), before) || duplicateIn && !sameFields(getChapter(duplicateIn.id), duplicateIn)) {
|
|
44355
|
+
throw new ApiError("\u7AE0\u8282\u5728\u5019\u9009\u751F\u6210\u540E\u53D1\u751F\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u51C6\u5907\u5019\u9009", 409);
|
|
44356
|
+
}
|
|
44357
|
+
}
|
|
44358
|
+
if (!sameFields(batch.orderBefore, batch.orderAfter)) setChapterPositions(run2.novelId, batch.orderAfter);
|
|
44359
|
+
for (const entry of batch.entries) {
|
|
44360
|
+
entry.saved = updateChapter(entry.before.id, entry.after.content === void 0 ? entry.after : { ...entry.after, wordCount: countWords(entry.after.content) });
|
|
44361
|
+
}
|
|
44362
|
+
change.appliedId = change.targetId;
|
|
44363
|
+
change.state = "applied";
|
|
44364
|
+
markArchivesStaleAfter(run2.novelId, -1);
|
|
44365
|
+
}
|
|
44366
|
+
function undoChapterBatch(run2, change) {
|
|
44367
|
+
const batch = change.chapterBatch;
|
|
44368
|
+
const appliedTitles = { ...batch.titles, ...Object.fromEntries(batch.entries.filter((entry) => entry.after.title !== void 0).map((entry) => [entry.before.id, entry.after.title])) };
|
|
44369
|
+
if (!sameFields(chapterPositions(run2.novelId, /* @__PURE__ */ new Set([batch.volumeId])), batch.orderAfter) || !sameFields(savedTitles(run2, batch.volumeId), appliedTitles) || batch.entries.some((entry) => entry.before.novelId !== run2.novelId || !sameFields(getChapter(entry.before.id), entry.saved))) {
|
|
44370
|
+
throw new ApiError("\u7AE0\u8282\u6216\u76EE\u5F55\u5DF2\u6709\u540E\u7EED\u4FEE\u6539\uFF0C\u4E0D\u80FD\u8986\u76D6\u64A4\u56DE", 409);
|
|
44371
|
+
}
|
|
44372
|
+
if (!sameFields(batch.orderBefore, batch.orderAfter)) setChapterPositions(run2.novelId, batch.orderBefore);
|
|
44373
|
+
for (const { before, after } of batch.entries) {
|
|
44374
|
+
updateChapter(before.id, {
|
|
44375
|
+
...after.content !== void 0 && { content: before.content, wordCount: before.wordCount },
|
|
44376
|
+
...after.title !== void 0 && { title: before.title },
|
|
44377
|
+
...after.summary !== void 0 && { summary: before.summary }
|
|
44378
|
+
});
|
|
44379
|
+
}
|
|
44380
|
+
markArchivesStaleAfter(run2.novelId, -1);
|
|
44381
|
+
change.state = "reverted";
|
|
44382
|
+
}
|
|
44383
|
+
|
|
43941
44384
|
// src/yanfield/lib/ai/agent/store.ts
|
|
43942
44385
|
var linkReaders = {
|
|
43943
44386
|
chapter: getChapter,
|
|
@@ -44042,7 +44485,7 @@ function visibleEntity(kind, id2, novelId, chapterIndex = null, explicitlyRefere
|
|
|
44042
44485
|
function propose(run2, kind, targetId, patch3, reason2, title, visibility, persist = true) {
|
|
44043
44486
|
const after = validatePatch(kind, patch3);
|
|
44044
44487
|
if (targetId && run2.changes.some((c) => c.op === "delete" && c.kind === kind && c.targetId === targetId && c.state === "pending")) throw new ApiError("\u8FD9\u5F20\u8D44\u6599\u5DF2\u6709\u5F85\u786E\u8BA4\u7684\u5220\u9664\uFF1B\u5982\u9700\u6539\u4E3A\u4FEE\u6539\uFF0C\u8BF7\u5148\u4E22\u5F03\u5220\u9664\u5019\u9009", 409);
|
|
44045
|
-
if (kind === "chapter" && targetId && (run2.changes.some((c) => c.chapterDirectory && c.targetId === targetId && c.state === "pending") || run2.changes.some((c) => c.chapterSplit && c.state === "pending" && (c.targetId === targetId || c.chapterSplit.existing?.id === targetId)) || run2.changes.some((c) => c.chapterPair && c.state === "pending" && (c.targetId === targetId || c.chapterPair.second.id === targetId)))) {
|
|
44488
|
+
if (kind === "chapter" && targetId && (run2.changes.some((c) => c.chapterDirectory && c.targetId === targetId && c.state === "pending") || run2.changes.some((c) => c.chapterSplit && c.state === "pending" && (c.targetId === targetId || c.chapterSplit.existing?.id === targetId)) || run2.changes.some((c) => c.chapterPair && c.state === "pending" && (c.targetId === targetId || c.chapterPair.second.id === targetId)) || run2.changes.some((c) => c.chapterBatch && c.state === "pending" && c.chapterBatch.entries.some((entry) => entry.before.id === targetId || entry.duplicateIn?.id === targetId)))) {
|
|
44046
44489
|
throw new ApiError("\u8FD9\u4E9B\u7AE0\u8282\u5DF2\u6709\u5F85\u5BA1\u6539\u52A8\uFF0C\u8BF7\u5148\u5904\u7406\u540E\u518D\u7EE7\u7EED", 409);
|
|
44047
44490
|
}
|
|
44048
44491
|
const existing = run2.changes.find((c) => !c.op && c.kind === kind && c.targetId === targetId && c.state === "pending" && (targetId || c.title === title));
|
|
@@ -44188,10 +44631,11 @@ function applyChanges(id2, selections) {
|
|
|
44188
44631
|
if (!change) throw new ApiError("\u6539\u52A8\u4E0D\u5B58\u5728", 400);
|
|
44189
44632
|
if (change.state === "applied") continue;
|
|
44190
44633
|
if (change.state !== "pending") throw new ApiError("\u8FD9\u9879\u6539\u52A8\u5DF2\u7ED3\u675F", 409);
|
|
44191
|
-
if (change
|
|
44634
|
+
if (isChapterOperation(change)) {
|
|
44192
44635
|
if (choice.fields !== void 0 || choice.blocks !== void 0) throw new ApiError("\u8BF7\u6574\u4F53\u5E94\u7528\u7AE0\u8282\u64CD\u4F5C\u5019\u9009", 400);
|
|
44193
44636
|
if (change.chapterSplit) applyChapterSplit(value, change);
|
|
44194
44637
|
else if (change.chapterPair) applyChapterPair(value, change);
|
|
44638
|
+
else if (change.chapterBatch) applyChapterBatch(value, change);
|
|
44195
44639
|
else applyChapterDirectoryAction(value, change);
|
|
44196
44640
|
continue;
|
|
44197
44641
|
}
|
|
@@ -44272,6 +44716,10 @@ function undoChanges(id2) {
|
|
|
44272
44716
|
undoChapterPair(value, c);
|
|
44273
44717
|
continue;
|
|
44274
44718
|
}
|
|
44719
|
+
if (c.chapterBatch) {
|
|
44720
|
+
undoChapterBatch(value, c);
|
|
44721
|
+
continue;
|
|
44722
|
+
}
|
|
44275
44723
|
if (c.op === "delete") {
|
|
44276
44724
|
deleted.push(c);
|
|
44277
44725
|
continue;
|
|
@@ -45809,9 +46257,9 @@ function demoChat(messages) {
|
|
|
45809
46257
|
}
|
|
45810
46258
|
function demoCardFill(user) {
|
|
45811
46259
|
const title = user.match(/标题:\s*\n?([^\n]+)/)?.[1]?.trim() || "\u8FD9\u6761\u8BBE\u5B9A";
|
|
45812
|
-
const
|
|
46260
|
+
const summary2 = user.match(/摘要:\s*\n?([^\n]+)/)?.[1]?.trim();
|
|
45813
46261
|
return JSON.stringify({
|
|
45814
|
-
summary:
|
|
46262
|
+
summary: summary2 || `${title}\u53EA\u5199\u5B83\u81EA\u5DF1\u7684\u4E8B\u5B9E\u3002`,
|
|
45815
46263
|
content: `${title}\u53EA\u5C5E\u4E8E\u8FD9\u5F20\u5361\u3002\u4E0D\u5411\u4F5C\u8005\u63D0\u95EE\uFF0C\u4E5F\u4E0D\u628A\u5176\u4ED6\u5730\u65B9\u5C55\u5F00\u6210\u5B8C\u6574\u6761\u76EE\u3002`
|
|
45816
46264
|
});
|
|
45817
46265
|
}
|
|
@@ -46911,9 +47359,9 @@ function buildDemoArchive(chapterId) {
|
|
|
46911
47359
|
const world = listWorld(novelId).slice(0, 2);
|
|
46912
47360
|
const foreshadows = listForeshadows(novelId).slice(0, 2);
|
|
46913
47361
|
const plain2 = chapter ? htmlToText(chapter.content).replace(/\s+/g, " ").trim() : "";
|
|
46914
|
-
const
|
|
47362
|
+
const summary2 = blueprint?.goal || plain2.slice(0, 120) || "\u672C\u7AE0\u63A8\u8FDB\u4E86\u4E3B\u7EBF\u51B2\u7A81\u3002";
|
|
46915
47363
|
return {
|
|
46916
|
-
chapterSummary:
|
|
47364
|
+
chapterSummary: summary2,
|
|
46917
47365
|
characterStates: characters.map((character) => ({
|
|
46918
47366
|
name: character.name,
|
|
46919
47367
|
state: character.currentState || "\u672C\u7AE0\u7ED3\u675F\u65F6\u60C5\u7EEA\u7D27\u7EF7\uFF0C\u4ECD\u672A\u505A\u51FA\u6700\u7EC8\u51B3\u5B9A",
|
|
@@ -46921,7 +47369,7 @@ function buildDemoArchive(chapterId) {
|
|
|
46921
47369
|
})),
|
|
46922
47370
|
settingStates: world.map((setting) => ({ title: setting.title, state: "\u672C\u7AE0\u8865\u5145\u4E86\u4E00\u6761\u4F7F\u7528\u9650\u5236" })),
|
|
46923
47371
|
ledger: [],
|
|
46924
|
-
timeline: [{ storyTime: "\u672C\u7AE0\u5F53\u591C", event:
|
|
47372
|
+
timeline: [{ storyTime: "\u672C\u7AE0\u5F53\u591C", event: summary2 }],
|
|
46925
47373
|
foreshadows: foreshadows.map((foreshadow) => ({ title: foreshadow.title, status: foreshadow.status, note: "\u672C\u7AE0\u6709\u63A8\u8FDB" })),
|
|
46926
47374
|
conflicts: []
|
|
46927
47375
|
};
|
|
@@ -47017,6 +47465,9 @@ function requestedChapterTool(message) {
|
|
|
47017
47465
|
case "\u8DE8\u7AE0\u79FB\u52A8\u6BB5\u843D":
|
|
47018
47466
|
case "move paragraphs between chapters":
|
|
47019
47467
|
return "move_chapter_blocks";
|
|
47468
|
+
case "\u6279\u91CF\u6574\u7406\u7AE0\u8282":
|
|
47469
|
+
case "organize chapters":
|
|
47470
|
+
return "organize_chapters";
|
|
47020
47471
|
}
|
|
47021
47472
|
}
|
|
47022
47473
|
|
|
@@ -47074,15 +47525,16 @@ var proseTarget = {
|
|
|
47074
47525
|
};
|
|
47075
47526
|
var words = external_exports.number().int().min(1).max(8e3).optional();
|
|
47076
47527
|
var minimumWords = words.describe("Only a minimum number the author explicitly required. Use words for the approximate target.");
|
|
47528
|
+
var inlineEdits = external_exports.array(external_exports.strictObject({
|
|
47529
|
+
original: external_exports.string().min(1).max(4e3),
|
|
47530
|
+
replacement: external_exports.string().max(4e3)
|
|
47531
|
+
})).min(1).max(30);
|
|
47077
47532
|
var proseSchema = external_exports.discriminatedUnion("mode", [
|
|
47078
47533
|
external_exports.strictObject({
|
|
47079
47534
|
...proseTarget,
|
|
47080
47535
|
mode: external_exports.literal("patch"),
|
|
47081
47536
|
id,
|
|
47082
|
-
edits:
|
|
47083
|
-
original: external_exports.string().min(1).max(4e3),
|
|
47084
|
-
replacement: external_exports.string().max(4e3)
|
|
47085
|
-
})).min(1).max(30)
|
|
47537
|
+
edits: inlineEdits
|
|
47086
47538
|
}),
|
|
47087
47539
|
external_exports.strictObject({ ...proseTarget, mode: external_exports.literal("selection"), id, words }),
|
|
47088
47540
|
external_exports.strictObject({ ...proseTarget, mode: external_exports.literal("append"), id, words, minimumWords }),
|
|
@@ -47137,17 +47589,30 @@ var moveChapterBlocksSchema = external_exports.strictObject({
|
|
|
47137
47589
|
]),
|
|
47138
47590
|
reason
|
|
47139
47591
|
});
|
|
47592
|
+
var organizeChaptersSchema = external_exports.strictObject({
|
|
47593
|
+
changes: external_exports.array(external_exports.strictObject({
|
|
47594
|
+
id,
|
|
47595
|
+
title: chapterTitle.optional(),
|
|
47596
|
+
summary: external_exports.string().trim().max(2e3).optional(),
|
|
47597
|
+
transition: external_exports.strictObject({ edge: external_exports.enum(["start", "end"]), text: external_exports.string().trim().min(1).max(1e3) }).optional().describe("Insert a short plain-text transition at the beginning or end of the final chapter text."),
|
|
47598
|
+
inlineEdits: inlineEdits.optional().describe("Exact single-paragraph edits in the retained chapter text."),
|
|
47599
|
+
duplicateTailIn: id.optional().describe("Existing chapter already containing the source's duplicated ending. The server verifies and trims the exact duplicated suffix; no copied prose or anchor needed.")
|
|
47600
|
+
})).max(30).default([]),
|
|
47601
|
+
moves: external_exports.array(external_exports.strictObject({ id, anchorId: id, placement: external_exports.enum(["before", "after"]) })).max(30).default([]),
|
|
47602
|
+
reason
|
|
47603
|
+
});
|
|
47140
47604
|
var definitions = {
|
|
47141
47605
|
search: [searchSchema, "Find chapters or cards by name, title or alias. Omit kind for the book overview."],
|
|
47142
47606
|
read: [readSchema, "Read a specific chapter, outline, card or archive. Follow nextOffset to read long material."],
|
|
47143
47607
|
write: [writeSchema.extend({ items: external_exports.array(itemSchema).min(1).max(20) }), "Stage one or many cards or outlines. Modify only requested fields. Read existing targets first. Include evidence for fields taken from a prose candidate or when the author requests quotations. Put occupations in identity and narrative roles in role."],
|
|
47144
|
-
edit_prose: [proseSchema, "Stage prose for review.
|
|
47608
|
+
edit_prose: [proseSchema, "Stage prose for review. Patch only replaces an exact unique excerpt within one paragraph. For a duplicated chapter ending, use organize_chapters with duplicateTailIn; for a transition paragraph, use organize_chapters with transition. Selection needs an editor selection, append preserves prior prose, and rewrite is for new prose or a requested full rewrite."],
|
|
47145
47609
|
split_chapter: [splitChapterSchema, "Stage a chapter split as one review item. Read the saved source chapter first, then quote the start of the first paragraph of the second half. This preserves the original paragraphs and puts the second half immediately after the source. When repairing a partial split, read and reuse the already saved second half."],
|
|
47146
47610
|
move_chapter: [moveChapterSchema, "Stage moving a saved chapter immediately before or after another saved chapter, including across volumes. Read both chapters first. Include title only if the author also requested a rename."],
|
|
47147
47611
|
rename_chapter: [renameChapterSchema, "Stage changing a saved chapter title. Read the chapter first. A rename does not move it."],
|
|
47148
47612
|
delete_chapter: [deleteChapterSchema, "Stage deleting one saved chapter only when the author explicitly requested deleting that entire chapter. Read the chapter first. The review lists any linked material that blocks deletion."],
|
|
47149
47613
|
merge_chapters: [mergeChaptersSchema, "Stage merging two adjacent saved chapters in the same volume. Read both. Keep their prose and formatting in order, retain the first chapter and remove the second. Only set a new title if requested. Use this instead of rewriting prose or deleting a chapter separately."],
|
|
47150
47614
|
move_chapter_blocks: [moveChapterBlocksSchema, "Stage moving a continuous block range between two saved chapters as one review item. Read both first. Use edge and count for first or last N paragraphs, or quote unique block starts. Both chapters remain. Use this instead of separate prose edits."],
|
|
47615
|
+
organize_chapters: [organizeChaptersSchema, "Stage related chapter repairs, ordering, titles, summaries, inline edits and opening/closing transitions in one volume. Later calls in the same run update the same proposal. Use chapter IDs from search. For duplicateTailIn, the server compares saved paragraphs and trims only the source. Read every page before writing a summary. Use transition to add a bridge paragraph without rewriting existing prose."],
|
|
47151
47616
|
delete: [deleteSchema, "Stage deletion of one entire saved card, only when explicitly requested. Read the card first."]
|
|
47152
47617
|
};
|
|
47153
47618
|
var agentTools = Object.keys(definitions).map((name3) => {
|
|
@@ -47229,17 +47694,19 @@ function stageFields(input2, reason2, run2, workspace, prior) {
|
|
|
47229
47694
|
const fromPrior = draft && prior?.changes.includes(draft);
|
|
47230
47695
|
const actualId = draft ? draft.targetId : id2 ?? null;
|
|
47231
47696
|
const isCard = kind === "character" || kind === "location" || kind === "world" || kind === "foreshadow";
|
|
47232
|
-
if (id2 && !workspace.observed.has(key)
|
|
47697
|
+
if (id2 && !workspace.observed.has(key) && (kind !== "blueprint" || input2.sourceChapterId !== id2 || draft || readEntity(kind, id2, run2.novelId))) {
|
|
47698
|
+
throw new Error("\u4FEE\u6539\u524D\u8BF7\u5148\u8BFB\u53D6\u76EE\u6807\u5BF9\u8C61");
|
|
47699
|
+
}
|
|
47233
47700
|
if (draft?.op === "delete") throw new Error("\u8FD9\u5F20\u8D44\u6599\u5DF2\u6709\u5F85\u786E\u8BA4\u7684\u5220\u9664\uFF1B\u5982\u9700\u6539\u4E3A\u4FEE\u6539\uFF0C\u8BF7\u5148\u4E22\u5F03\u5220\u9664\u5019\u9009");
|
|
47234
47701
|
if (draft?.evidence?.some((evidence2) => evidence2.candidate) && fromPrior) {
|
|
47235
47702
|
throw new Error("\u8FD9\u6761\u8D44\u6599\u4F9D\u8D56\u5C1A\u672A\u786E\u8BA4\u7684\u6B63\u6587\uFF0C\u8BF7\u5148\u5BA1\u9605\u8BE5\u6B63\u6587");
|
|
47236
47703
|
}
|
|
47237
47704
|
if (kind === "blueprint" && input2.sourceChapterId) {
|
|
47238
|
-
const source = workspace.
|
|
47239
|
-
if (
|
|
47705
|
+
const source = workspace.reviewedChapterBody(input2.sourceChapterId);
|
|
47706
|
+
if (source === void 0) {
|
|
47240
47707
|
throw new Error("\u8BF7\u6309 nextOffset \u8BFB\u5B8C\u5F53\u524D\u7AE0\u6B63\u6587\uFF0C\u518D\u751F\u6210\u7AE0\u7EB2");
|
|
47241
47708
|
}
|
|
47242
|
-
if (!stripHtml(
|
|
47709
|
+
if (!stripHtml(source)) throw new Error("\u5F53\u524D\u7AE0\u8282\u8FD8\u6CA1\u6709\u53EF\u7528\u4E8E\u6574\u7406\u7AE0\u7EB2\u7684\u6B63\u6587");
|
|
47243
47710
|
}
|
|
47244
47711
|
validateLinks(kind, fields, run2.novelId, actualId);
|
|
47245
47712
|
const cited = "evidence" in input2 ? input2.evidence?.map((citation) => {
|
|
@@ -47360,7 +47827,8 @@ var AGENT_INSTRUCTIONS = `\u4F60\u662F\u781A\u7530\u5199\u4F5C\u52A9\u624B\u3002
|
|
|
47360
47827
|
\u3010\u62C6\u7AE0\u3011\u7528 split_chapter\uFF0C\u5148\u8BFB\u5DF2\u4FDD\u5B58\u7684\u539F\u7AE0\uFF0C\u518D\u9010\u5B57\u5F15\u7528\u65B0\u7AE0\u7B2C\u4E00\u6BB5\u5F00\u5934\u4F5C\u4E3A\u5207\u70B9\u3002\u5207\u70B9\u6240\u5728\u6BB5\u53CA\u4E4B\u540E\u7684\u6B63\u6587\u539F\u6837\u8FDB\u5165\u4E0B\u4E00\u7AE0\u3002\u82E5\u540E\u534A\u7AE0\u5DF2\u7ECF\u5B58\u5728\uFF0C\u5148\u8BFB\u5B83\u5E76\u6307\u5B9A existing\u3002\u4E0D\u8981\u901A\u8FC7\u6539\u5199\u3001\u5220\u9664\u957F\u9009\u533A\u6216\u5355\u72EC\u65B0\u5EFA\u6765\u6A21\u62DF\u62C6\u7AE0\u3002
|
|
47361
47828
|
\u3010\u76EE\u5F55\u3011\u79FB\u52A8\u7AE0\u8282\u7528 move_chapter\uFF0C\u4EE5\u53E6\u4E00\u7AE0\u4E3A\u5B9A\u4F4D\u3002\u4F5C\u8005\u540C\u65F6\u8981\u6C42\u6539\u540D\u65F6\u53EF\u4F20 title\uFF1B\u53EA\u6539\u540D\u7528 rename_chapter\u3002\u660E\u786E\u8981\u6C42\u5220\u9664\u6574\u7AE0\u65F6\u7528 delete_chapter\uFF1B\u6709\u4F9D\u8D56\u7684\u7AE0\u8282\u4E0D\u80FD\u5220\u9664\uFF0C\u62A5\u544A\u53D7\u5F71\u54CD\u7684\u5173\u8054\u3002\u4E0D\u8981\u628A\u6807\u9898\u4E2D\u7684\u7AE0\u53F7\u5F53\u6210\u76EE\u5F55\u4F4D\u7F6E\u3002
|
|
47362
47829
|
\u3010\u8DE8\u7AE0\u3011\u5408\u5E76\u76F8\u90BB\u4E24\u7AE0\u7528 merge_chapters\uFF1B\u540E\u7AE0\u82E5\u6709\u5173\u8054\uFF0C\u6309\u56DE\u6267\u8BF4\u660E\u5E76\u505C\u5728\u5F85\u5904\u7406\u72B6\u6001\u3002\u8DE8\u7AE0\u79FB\u52A8\u8FDE\u7EED\u6BB5\u843D\u7528 move_chapter_blocks\uFF1B\u4E24\u7AE0\u90FD\u4FDD\u7559\u3002\u8BFB\u53D6\u4E24\u7AE0\u540E\u518D\u64CD\u4F5C\uFF0C\u6CBF\u7528\u539F\u6587\u548C\u683C\u5F0F\u3002\u4E0D\u8981\u5206\u6210\u591A\u4E2A\u6B63\u6587\u6539\u52A8\u6A21\u62DF\u8FD9\u4E24\u9879\u3002
|
|
47363
|
-
\u3010\
|
|
47830
|
+
\u3010\u6279\u91CF\u6574\u7406\u3011\u540C\u4E00\u5377\u5185\u6709\u591A\u9879\u5173\u8054\u7684\u7AE0\u8282\u6539\u52A8\uFF0C\u7528 organize_chapters \u4E00\u8D77\u63D0\u4EA4\uFF0C\u5305\u62EC\u76EE\u5F55\u79FB\u52A8\u3001\u6807\u9898\u3001\u77ED\u6458\u8981\u548C\u5DF2\u62C6\u7AE0\u8282\u7684\u91CD\u590D\u7AE0\u5C3E\u3002\u82E5\u540E\u534A\u7AE0\u5DF2\u7ECF\u5B58\u5728\u4E14\u539F\u7AE0\u4ECD\u6709\u91CD\u590D\u7ED3\u5C3E\uFF0C\u7528 duplicateTailIn \u6307\u5B9A\u5DF2\u7ECF\u4FDD\u7559\u8BE5\u6BB5\u7684\u7AE0\u8282\uFF0C\u7531\u5DE5\u5177\u505A\u7CBE\u786E\u6BD4\u5BF9\uFF1B\u4E0D\u8981\u7528 edit_prose \u53CD\u590D\u590D\u5199\u6216\u5220\u9664\u6574\u6BB5\u91CD\u590D\u6B63\u6587\u3002\u76EE\u5F55\u3001\u6807\u9898\u548C\u91CD\u590D\u7AE0\u5C3E\u7528 search \u53D6\u5F97\u7AE0\u8282 ID \u540E\u5373\u53EF\u63D0\u4EA4\uFF1B\u6279\u91CF\u5019\u9009\u751F\u6210\u540E\uFF0C\u540C\u4E00\u8F6E\u540E\u7EED\u7684 organize_chapters \u4F1A\u8865\u8FDB\u540C\u4E00\u5F20\u5019\u9009\uFF0C\u7EE7\u7EED\u5904\u7406\u5269\u4F59\u7AE0\u8282\u3002\u9700\u8981\u8865\u7AE0\u9996\u3001\u7AE0\u5C3E\u8FC7\u6E21\u65F6\u7528 transition \u63D2\u5165\u72EC\u7ACB\u77ED\u6BB5\uFF0C\u4E0D\u8C03\u7528 edit_prose \u6A2A\u8DE8\u6BB5\u843D\u3002\u62DF\u5199\u6458\u8981\u987B\u5148\u6309 nextOffset \u8BFB\u5B8C\u6574\u7AE0\uFF1B\u82E5\u5DF2\u51C6\u5907\u622A\u5C3E\u6216\u8FC7\u6E21\uFF0C\u91CD\u65B0 read \u53EF\u8BFB\u53D6\u5019\u9009\u6B63\u6587\uFF0C\u518D\u5199\u6458\u8981\u3002\u53EA\u4E3A\u4F5C\u8005\u8981\u6C42\u7684\u4E8B\u9879\u51C6\u5907\u5019\u9009\u3002
|
|
47831
|
+
\u3010\u56DE\u6267\u3011\u6539\u52A8\u5DE5\u5177\u7684 reason \u9010\u5B57\u5F15\u7528\u652F\u6301\u672C\u9879\u64CD\u4F5C\u7684\u672C\u8F6E\u6307\u4EE4\u3002\u5DE5\u5177\u8FD4\u56DE\u6210\u529F\u53EA\u8868\u793A\u5019\u9009\u5DF2\u51C6\u5907\uFF0C\u7531\u4F5C\u8005\u786E\u8BA4\u540E\u624D\u4FDD\u5B58\u3002\u9010\u9879\u6838\u5BF9\u660E\u786E\u8981\u6C42\u7684\u7ED3\u679C\uFF1B\u53EA\u4FEE\u6B63\u5931\u8D25\u9879\uFF0C\u5E76\u4F7F\u7528\u540C\u4E00\u76EE\u6807 ID\u3002\u82E5\u660E\u786E\u5728\u5220\u91CD\u590D\u7AE0\u5C3E\u4E14\u56DE\u6267\u8FD4\u56DE forDuplicatedTail\uFF0C\u6539\u7528\u56DE\u6267\u91CC\u7684 organize_chapters \u53C2\u6570\u51C6\u5907\u5019\u9009\uFF0C\u65E0\u9700\u4E2D\u9014\u786E\u8BA4\u6216\u7EE7\u7EED\u8BD5 patch\u3002\u5DF2\u6709\u6279\u91CF\u5019\u9009\u65F6\uFF0C\u6BB5\u5185\u5C0F\u6539\u53EF\u7528 inlineEdits \u52A0\u5165\u540C\u4E00\u5019\u9009\u3002\u5B57\u6570\u4E0D\u8DB3\u65F6\u7528\u56DE\u6267 retry \u6307\u5B9A\u7684 mode \u548C id \u4FEE\u8BA2\u540C\u4E00\u5019\u9009\uFF0C\u4E0D\u80FD\u6539\u7528 patch\u3002\u56DE\u6267\u4E2D\u4ECD\u672A\u5B8C\u6210\u7684\u9879\u76EE\u8BF7\u6307\u51FA\uFF0C\u907F\u514D\u628A\u90E8\u5206\u5019\u9009\u79F0\u4F5C\u5168\u90E8\u5DF2\u5B8C\u6210\u3002\u56DE\u590D\u4E0E\u65B0\u5199\u5B57\u6BB5\u5747\u987B\u7528 current.request \u4E2D\u64CD\u4F5C\u6307\u4EE4\u7684\u8BED\u8A00\u3002\u5373\u4F7F\u5DE5\u5177\u56DE\u6267\u3001\u5F53\u524D\u7AE0\u3001\u65E7\u56DE\u590D\u6216\u754C\u9762\u662F\u5176\u4ED6\u8BED\u8A00\uFF0C\u4ECD\u4F7F\u7528 current.request \u7684\u64CD\u4F5C\u6307\u4EE4\u8BED\u8A00\u3002\u6700\u7EC8\u56DE\u590D\u7528\u5BF9\u8C61\u540D\u79F0\u548C\u5B9E\u9645\u6539\u52A8\u8BF4\u660E\uFF0C\u5185\u90E8 ID \u7559\u5728\u5DE5\u5177\u56DE\u6267\u4E2D\u3002`;
|
|
47364
47832
|
|
|
47365
47833
|
// src/yanfield/lib/ai/agent/receipt.ts
|
|
47366
47834
|
var normalized2 = (text3) => text3.replace(/[\s\p{P}\p{S}]/gu, "");
|
|
@@ -47432,21 +47900,6 @@ async function* streamThoughts(run2, chunks, withinStep = false) {
|
|
|
47432
47900
|
if (thought) yield { type: "agent-thinking", phase: "end", thought };
|
|
47433
47901
|
}
|
|
47434
47902
|
|
|
47435
|
-
// src/yanfield/lib/ai/agent/types.ts
|
|
47436
|
-
function isChapterOperation(change) {
|
|
47437
|
-
return Boolean(change.chapterSplit || change.chapterDirectory || change.chapterPair);
|
|
47438
|
-
}
|
|
47439
|
-
var ENTITY_LABEL = {
|
|
47440
|
-
chapter: "\u6B63\u6587",
|
|
47441
|
-
blueprint: "\u7AE0\u7EB2",
|
|
47442
|
-
character: "\u89D2\u8272",
|
|
47443
|
-
world: "\u8BBE\u5B9A",
|
|
47444
|
-
location: "\u5730\u70B9",
|
|
47445
|
-
foreshadow: "\u4F0F\u7B14",
|
|
47446
|
-
outline: "\u603B\u7EB2",
|
|
47447
|
-
"volume-outline": "\u5377\u7EB2"
|
|
47448
|
-
};
|
|
47449
|
-
|
|
47450
47903
|
// src/yanfield/lib/ai/agent/loop.ts
|
|
47451
47904
|
var labels = {
|
|
47452
47905
|
search: "\u67E5\u627E\u76F8\u5173\u8D44\u6599",
|
|
@@ -47459,11 +47912,13 @@ var labels = {
|
|
|
47459
47912
|
rename_chapter: "\u51C6\u5907\u91CD\u547D\u540D\u7AE0\u8282",
|
|
47460
47913
|
delete_chapter: "\u51C6\u5907\u5220\u9664\u7AE0\u8282",
|
|
47461
47914
|
merge_chapters: "\u51C6\u5907\u5408\u5E76\u7AE0\u8282",
|
|
47462
|
-
move_chapter_blocks: "\u51C6\u5907\u8DE8\u7AE0\u79FB\u52A8\u6BB5\u843D"
|
|
47915
|
+
move_chapter_blocks: "\u51C6\u5907\u8DE8\u7AE0\u79FB\u52A8\u6BB5\u843D",
|
|
47916
|
+
organize_chapters: "\u51C6\u5907\u6279\u91CF\u6574\u7406\u7AE0\u8282"
|
|
47463
47917
|
};
|
|
47464
47918
|
var MAX_ROUNDS = 20;
|
|
47465
47919
|
var MAX_CALLS = 60;
|
|
47466
|
-
var writingTools = /* @__PURE__ */ new Set(["write", "edit_prose", "delete", "split_chapter", "move_chapter", "rename_chapter", "delete_chapter", "merge_chapters", "move_chapter_blocks"]);
|
|
47920
|
+
var writingTools = /* @__PURE__ */ new Set(["write", "edit_prose", "delete", "split_chapter", "move_chapter", "rename_chapter", "delete_chapter", "merge_chapters", "move_chapter_blocks", "organize_chapters"]);
|
|
47921
|
+
var REASON_ERROR = "\u6539\u52A8\u539F\u56E0\u987B\u9010\u5B57\u5F15\u7528\u672C\u8F6E\u4F5C\u8005\u6307\u4EE4\uFF0C\u8BF7\u6838\u5BF9\u540E\u91CD\u8BD5";
|
|
47467
47922
|
function target(change) {
|
|
47468
47923
|
return { kind: change.kind, id: change.targetId ?? change.id, title: change.title, changeId: change.id };
|
|
47469
47924
|
}
|
|
@@ -47484,6 +47939,7 @@ async function* runTools(input2) {
|
|
|
47484
47939
|
const initial = messages.length;
|
|
47485
47940
|
const failures = /* @__PURE__ */ new Map();
|
|
47486
47941
|
const attempts = /* @__PURE__ */ new Map();
|
|
47942
|
+
const tailRecovery = /* @__PURE__ */ new Map();
|
|
47487
47943
|
let callsMade = 0;
|
|
47488
47944
|
let outputRetry = false;
|
|
47489
47945
|
const failure2 = (key, tool, title, error62) => {
|
|
@@ -47495,10 +47951,11 @@ async function* runTools(input2) {
|
|
|
47495
47951
|
failures.delete(key);
|
|
47496
47952
|
attempts.delete(key);
|
|
47497
47953
|
};
|
|
47498
|
-
const assertReason = (reason2) => {
|
|
47954
|
+
const assertReason = (reason2, key) => {
|
|
47499
47955
|
if (!reason2.trim() || !request.message.includes(reason2)) {
|
|
47500
|
-
throw new ApiError(
|
|
47956
|
+
throw new ApiError(REASON_ERROR, 400);
|
|
47501
47957
|
}
|
|
47958
|
+
recovered(`${key}:reason`);
|
|
47502
47959
|
};
|
|
47503
47960
|
const titleOf2 = (item) => {
|
|
47504
47961
|
if (!item || typeof item !== "object") return "";
|
|
@@ -47509,6 +47966,7 @@ async function* runTools(input2) {
|
|
|
47509
47966
|
async function* execute(call, step) {
|
|
47510
47967
|
let key = `${call.name}:arguments`;
|
|
47511
47968
|
let title = "";
|
|
47969
|
+
let patch3;
|
|
47512
47970
|
try {
|
|
47513
47971
|
if (allowedTools && !allowedTools.has(call.name)) {
|
|
47514
47972
|
step.status = "error";
|
|
@@ -47547,16 +48005,18 @@ async function* runTools(input2) {
|
|
|
47547
48005
|
}
|
|
47548
48006
|
if (call.name === "write") {
|
|
47549
48007
|
const args = writeSchema.parse(raw);
|
|
47550
|
-
assertReason(args.reason);
|
|
48008
|
+
assertReason(args.reason, key);
|
|
47551
48009
|
recovered(key);
|
|
47552
48010
|
const items = args.items.map((value, index) => {
|
|
47553
48011
|
const itemTitle = titleOf2(value);
|
|
47554
48012
|
const { kind, id: id2 } = value && typeof value === "object" ? value : {};
|
|
47555
48013
|
const targetId = id2 ?? (kind === "blueprint" ? run2.chapterId : kind === "outline" ? run2.novelId : void 0);
|
|
47556
48014
|
const itemKey = `write:${String(kind ?? "")}:${String(targetId ?? itemTitle).normalize("NFKC").trim().toLowerCase() || index + 1}`;
|
|
48015
|
+
let sourceChapterId;
|
|
47557
48016
|
try {
|
|
47558
48017
|
if ((attempts.get(itemKey) ?? 0) >= 3) throw new Error("\u6B64\u9879\u5DF2\u591A\u6B21\u5931\u8D25\uFF0C\u8BF7\u6838\u5BF9\u540E\u518D\u7EE7\u7EED");
|
|
47559
48018
|
const item = itemSchema.parse(value);
|
|
48019
|
+
if (item.kind === "blueprint") sourceChapterId = item.sourceChapterId;
|
|
47560
48020
|
const change = stageFields(item, args.reason, run2, workspace, prior);
|
|
47561
48021
|
step.targets ??= [];
|
|
47562
48022
|
if (!step.targets.some((entry) => entry.changeId === change.id)) step.targets.push(target(change));
|
|
@@ -47573,11 +48033,24 @@ async function* runTools(input2) {
|
|
|
47573
48033
|
...possiblyRemoved.length ? { possiblyRemoved: possiblyRemoved.slice(0, 3) } : {}
|
|
47574
48034
|
};
|
|
47575
48035
|
} catch (error62) {
|
|
48036
|
+
const issue2 = toolError(error62);
|
|
48037
|
+
if (sourceChapterId && issue2.message === "\u8BF7\u6309 nextOffset \u8BFB\u5B8C\u5F53\u524D\u7AE0\u6B63\u6587\uFF0C\u518D\u751F\u6210\u7AE0\u7EB2") {
|
|
48038
|
+
failures.set(itemKey, { tool: call.name, title: itemTitle, error: issue2 });
|
|
48039
|
+
return {
|
|
48040
|
+
index: index + 1,
|
|
48041
|
+
kind,
|
|
48042
|
+
title: itemTitle,
|
|
48043
|
+
ok: false,
|
|
48044
|
+
error: issue2,
|
|
48045
|
+
retryable: true,
|
|
48046
|
+
nextRead: { kind: "chapter", id: sourceChapterId, offset: workspace.chapterPages.get(sourceChapterId) ?? 0 }
|
|
48047
|
+
};
|
|
48048
|
+
}
|
|
47576
48049
|
return {
|
|
47577
48050
|
index: index + 1,
|
|
47578
48051
|
kind,
|
|
47579
48052
|
title: itemTitle,
|
|
47580
|
-
...failure2(itemKey, call.name, itemTitle,
|
|
48053
|
+
...failure2(itemKey, call.name, itemTitle, issue2)
|
|
47581
48054
|
};
|
|
47582
48055
|
}
|
|
47583
48056
|
});
|
|
@@ -47594,7 +48067,7 @@ async function* runTools(input2) {
|
|
|
47594
48067
|
if (call.name === "delete") {
|
|
47595
48068
|
const args = deleteSchema.parse(raw);
|
|
47596
48069
|
key = `delete:${args.kind}:${args.id}`;
|
|
47597
|
-
assertReason(args.reason);
|
|
48070
|
+
assertReason(args.reason, key);
|
|
47598
48071
|
workspace.permitted(args.kind, args.id);
|
|
47599
48072
|
const row = workspace.observed.get(`${args.kind}:${args.id}`);
|
|
47600
48073
|
if (!row || workspace.candidate(args.kind, args.id)) throw new Error("\u5220\u9664\u524D\u8BF7\u5148\u8BFB\u53D6\u76EE\u6807\u5BF9\u8C61");
|
|
@@ -47615,7 +48088,7 @@ async function* runTools(input2) {
|
|
|
47615
48088
|
if (call.name === "split_chapter") {
|
|
47616
48089
|
const args = splitChapterSchema.parse(raw);
|
|
47617
48090
|
key = `split_chapter:${args.id}`;
|
|
47618
|
-
assertReason(args.reason);
|
|
48091
|
+
assertReason(args.reason, key);
|
|
47619
48092
|
if ((attempts.get(key) ?? 0) >= 3) throw new Error("\u6B64\u9879\u5DF2\u591A\u6B21\u5931\u8D25\uFF0C\u8BF7\u6838\u5BF9\u540E\u518D\u7EE7\u7EED");
|
|
47620
48093
|
const change = stageChapterSplit(run2, args, workspace.observed);
|
|
47621
48094
|
step.targets = [target(change)];
|
|
@@ -47633,10 +48106,50 @@ async function* runTools(input2) {
|
|
|
47633
48106
|
state: "pending"
|
|
47634
48107
|
};
|
|
47635
48108
|
}
|
|
48109
|
+
if (call.name === "organize_chapters") {
|
|
48110
|
+
const args = organizeChaptersSchema.parse(raw);
|
|
48111
|
+
key = `organize_chapters:${[...new Set([...args.changes, ...args.moves].map((item) => item.id))].sort().join(",")}`;
|
|
48112
|
+
assertReason(args.reason, key);
|
|
48113
|
+
if ((attempts.get(key) ?? 0) >= 3) throw new Error("\u6B64\u9879\u5DF2\u591A\u6B21\u5931\u8D25\uFF0C\u8BF7\u6838\u5BF9\u540E\u518D\u7EE7\u7EED");
|
|
48114
|
+
const previousContent = new Map(run2.changes.flatMap((change2) => change2.state === "pending" ? (change2.chapterBatch?.entries ?? []).map((entry) => [entry.before.id, entry.after.content]) : []));
|
|
48115
|
+
const change = stageChapterBatch(run2, args, workspace.observed, workspace.chapterPages);
|
|
48116
|
+
const batch = change.chapterBatch;
|
|
48117
|
+
for (const entry of batch.entries) {
|
|
48118
|
+
if (entry.after.content !== previousContent.get(entry.before.id)) workspace.chapterPages.delete(entry.before.id);
|
|
48119
|
+
const failed = `edit_prose:${entry.before.id}`;
|
|
48120
|
+
if (entry.duplicateIn && entry.duplicateIn.id === tailRecovery.get(failed)) {
|
|
48121
|
+
recovered(failed);
|
|
48122
|
+
tailRecovery.delete(failed);
|
|
48123
|
+
}
|
|
48124
|
+
}
|
|
48125
|
+
step.targets = [target(change)];
|
|
48126
|
+
step.detail = "\u5019\u9009\u5DF2\u51C6\u5907\uFF0C\u7B49\u5F85\u786E\u8BA4";
|
|
48127
|
+
recovered(key);
|
|
48128
|
+
recovered("organize_chapters:arguments");
|
|
48129
|
+
recovered("chapter-tool");
|
|
48130
|
+
return {
|
|
48131
|
+
ok: true,
|
|
48132
|
+
changeId: change.id,
|
|
48133
|
+
state: "pending",
|
|
48134
|
+
chapterCount: batch.entries.length,
|
|
48135
|
+
updates: batch.entries.map((entry) => ({
|
|
48136
|
+
id: entry.before.id,
|
|
48137
|
+
title: entry.after.title ?? entry.before.title,
|
|
48138
|
+
summary: entry.after.summary !== void 0,
|
|
48139
|
+
transition: Object.keys(entry.transitions ?? {})
|
|
48140
|
+
})),
|
|
48141
|
+
orderChanged: batch.orderBefore.some((entry, index) => entry.id !== batch.orderAfter[index].id),
|
|
48142
|
+
trimmed: batch.entries.filter((entry) => entry.removedBlocks).map((entry) => ({
|
|
48143
|
+
title: entry.before.title,
|
|
48144
|
+
duplicateIn: entry.duplicateIn?.title,
|
|
48145
|
+
paragraphs: entry.removedBlocks
|
|
48146
|
+
}))
|
|
48147
|
+
};
|
|
48148
|
+
}
|
|
47636
48149
|
if (call.name === "merge_chapters" || call.name === "move_chapter_blocks") {
|
|
47637
48150
|
const args = call.name === "merge_chapters" ? { ...mergeChaptersSchema.parse(raw), kind: "merge" } : { ...moveChapterBlocksSchema.parse(raw), kind: "transfer" };
|
|
47638
48151
|
key = `${call.name}:${args.id}:${args.secondId}`;
|
|
47639
|
-
assertReason(args.reason);
|
|
48152
|
+
assertReason(args.reason, key);
|
|
47640
48153
|
if ((attempts.get(key) ?? 0) >= 3) throw new Error("\u6B64\u9879\u5DF2\u591A\u6B21\u5931\u8D25\uFF0C\u8BF7\u6838\u5BF9\u540E\u518D\u7EE7\u7EED");
|
|
47641
48154
|
const change = stageChapterPair(run2, args, workspace.observed);
|
|
47642
48155
|
const pair = change.chapterPair;
|
|
@@ -47663,7 +48176,7 @@ async function* runTools(input2) {
|
|
|
47663
48176
|
if (call.name === "move_chapter" || call.name === "rename_chapter" || call.name === "delete_chapter") {
|
|
47664
48177
|
const args = call.name === "move_chapter" ? { ...moveChapterSchema.parse(raw), kind: "move" } : call.name === "rename_chapter" ? { ...renameChapterSchema.parse(raw), kind: "rename" } : { ...deleteChapterSchema.parse(raw), kind: "delete" };
|
|
47665
48178
|
key = `${call.name}:${args.id}`;
|
|
47666
|
-
assertReason(args.reason);
|
|
48179
|
+
assertReason(args.reason, key);
|
|
47667
48180
|
if ((attempts.get(key) ?? 0) >= 3) throw new Error("\u6B64\u9879\u5DF2\u591A\u6B21\u5931\u8D25\uFF0C\u8BF7\u6838\u5BF9\u540E\u518D\u7EE7\u7EED");
|
|
47668
48181
|
const change = stageChapterDirectoryAction(run2, args, workspace.observed);
|
|
47669
48182
|
step.targets = [target(change)];
|
|
@@ -47682,11 +48195,24 @@ async function* runTools(input2) {
|
|
|
47682
48195
|
}
|
|
47683
48196
|
if (call.name === "edit_prose") {
|
|
47684
48197
|
const args = proseSchema.parse(raw);
|
|
48198
|
+
if (args.mode === "patch") patch3 = args;
|
|
47685
48199
|
const requestedTitle = args.mode === "rewrite" ? args.title : void 0;
|
|
47686
48200
|
key = `edit_prose:${args.id ?? requestedTitle ?? run2.chapterId ?? ""}`;
|
|
47687
|
-
assertReason(args.reason);
|
|
48201
|
+
assertReason(args.reason, key);
|
|
47688
48202
|
if ((attempts.get(key) ?? 0) >= 3) throw new Error("\u6B64\u9879\u5DF2\u591A\u6B21\u5931\u8D25\uFF0C\u8BF7\u6838\u5BF9\u540E\u518D\u7EE7\u7EED");
|
|
47689
48203
|
title = requestedTitle ?? String(args.id && workspace.observed.get(`chapter:${args.id}`)?.title || "");
|
|
48204
|
+
if (args.mode === "patch" && !request.writingPreset && !args.organizeNotes && run2.changes.some((change2) => change2.state === "pending" && change2.chapterBatch?.entries.some((entry) => entry.before.id === args.id || entry.duplicateIn?.id === args.id))) {
|
|
48205
|
+
const change2 = stageChapterBatch(run2, {
|
|
48206
|
+
changes: [{ id: args.id, inlineEdits: args.edits }],
|
|
48207
|
+
moves: [],
|
|
48208
|
+
reason: args.reason
|
|
48209
|
+
}, workspace.observed, workspace.chapterPages);
|
|
48210
|
+
workspace.chapterPages.delete(args.id);
|
|
48211
|
+
step.targets = [target(change2)];
|
|
48212
|
+
step.detail = "\u5019\u9009\u5DF2\u51C6\u5907\uFF0C\u7B49\u5F85\u786E\u8BA4";
|
|
48213
|
+
recovered(key);
|
|
48214
|
+
return { ok: true, changeId: change2.id, title, state: "pending", groupedWithChapterBatch: true };
|
|
48215
|
+
}
|
|
47690
48216
|
const result = yield* edit(args);
|
|
47691
48217
|
const change = run2.changes.find((change2) => change2.id === result.changeId);
|
|
47692
48218
|
step.targets = [target(change)];
|
|
@@ -47717,6 +48243,31 @@ async function* runTools(input2) {
|
|
|
47717
48243
|
step.status = "error";
|
|
47718
48244
|
step.detail = issue2.message;
|
|
47719
48245
|
if (issue2.fields?.length) step.issues = [{ title, message: issue2.message, fields: issue2.fields }];
|
|
48246
|
+
if (issue2.message === REASON_ERROR) {
|
|
48247
|
+
return { ...failure2(`${key}:reason`, call.name, title, issue2), reasonExample: request.message.slice(0, 160).trimEnd() };
|
|
48248
|
+
}
|
|
48249
|
+
if (patch3 && (issue2.message === "\u9009\u533A\u5DF2\u53D8\u5316\u6216\u65E0\u6CD5\u5B9A\u4F4D\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u6B63\u6587" || issue2.message === "\u4FEE\u8BA2\u672A\u80FD\u4FDD\u7559\u539F\u6765\u7684\u6BB5\u843D\u7ED3\u6784\uFF0C\u8BF7\u91CD\u8BD5\u6216\u7F29\u5C0F\u9009\u533A")) {
|
|
48250
|
+
const hint = suggestChapterTailRepair(run2.novelId, patch3.id);
|
|
48251
|
+
step.detail = hint ? "\u6BB5\u5185\u4FEE\u6539\u672A\u5339\u914D\uFF0C\u5DF2\u627E\u5230\u53EF\u6838\u5BF9\u7684\u91CD\u590D\u7AE0\u5C3E" : "\u6BB5\u5185\u4FEE\u6539\u6CA1\u6709\u5339\u914D\u5230\u552F\u4E00\u7684\u539F\u6587";
|
|
48252
|
+
const error63 = { code: "PATCH_NOT_LOCATED", message: step.detail };
|
|
48253
|
+
const result = failure2(key, call.name, title, error63);
|
|
48254
|
+
if (!hint) return { ...result, patchScope: "single_paragraph_exact_excerpt" };
|
|
48255
|
+
const { removedText, ...match } = hint;
|
|
48256
|
+
const tail = stripHtml(removedText);
|
|
48257
|
+
if (patch3.edits.every((edit2) => !edit2.replacement.trim() && tail.includes(edit2.original.trim().slice(0, 24)))) {
|
|
48258
|
+
tailRecovery.set(key, hint.duplicateTailIn);
|
|
48259
|
+
}
|
|
48260
|
+
return {
|
|
48261
|
+
...result,
|
|
48262
|
+
patchScope: "single_paragraph_exact_excerpt",
|
|
48263
|
+
forDuplicatedTail: {
|
|
48264
|
+
tool: "organize_chapters",
|
|
48265
|
+
changes: [{ id: patch3.id, duplicateTailIn: match.duplicateTailIn }],
|
|
48266
|
+
retainedIn: match.title,
|
|
48267
|
+
matchingParagraphs: match.paragraphs
|
|
48268
|
+
}
|
|
48269
|
+
};
|
|
48270
|
+
}
|
|
47720
48271
|
return writingTools.has(call.name) ? failure2(key, call.name, title, issue2) : { ok: false, error: issue2 };
|
|
47721
48272
|
}
|
|
47722
48273
|
}
|
|
@@ -47819,88 +48370,6 @@ function candidateContext(change) {
|
|
|
47819
48370
|
return value;
|
|
47820
48371
|
}
|
|
47821
48372
|
|
|
47822
|
-
// src/yanfield/lib/ai/agent/prose-edit.ts
|
|
47823
|
-
function escapeProse(text3) {
|
|
47824
|
-
return text3.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
47825
|
-
}
|
|
47826
|
-
function writerPlainText(output2) {
|
|
47827
|
-
const text3 = output2.trim().replace(/^```(?:html|text)?\s*\n([\s\S]*?)\n```$/i, "$1").trim();
|
|
47828
|
-
return /^<p(?:\s[^>]*)?>[\s\S]*<\/p>$/i.test(text3) ? stripHtml(text3) : text3;
|
|
47829
|
-
}
|
|
47830
|
-
function prepareProseEdit(html, original, range) {
|
|
47831
|
-
const offsets = [];
|
|
47832
|
-
let text3 = "";
|
|
47833
|
-
let seenBlock = false;
|
|
47834
|
-
const add = (value, from, to) => {
|
|
47835
|
-
text3 += value;
|
|
47836
|
-
for (let i = 0; i < value.length; i++) offsets.push({ from, to });
|
|
47837
|
-
};
|
|
47838
|
-
for (const token of html.matchAll(/<[^>]*>|&(?:#\d+|#x[\da-f]+|[a-z][a-z\d]*);|[^<&]+|[<&]/gi)) {
|
|
47839
|
-
const [value] = token;
|
|
47840
|
-
const from = token.index;
|
|
47841
|
-
if (/^<(p|h[1-6]|pre)(?:\s|>)/i.test(value)) {
|
|
47842
|
-
if (seenBlock) add("\n", from, from);
|
|
47843
|
-
seenBlock = true;
|
|
47844
|
-
} else if (/^<br\b/i.test(value)) {
|
|
47845
|
-
add("\n", from, from + value.length);
|
|
47846
|
-
} else if (!/^<[^>]*>$/.test(value)) {
|
|
47847
|
-
const decoded = value.startsWith("&") ? stripHtml(value) || (value === " " || value === " " ? " " : value) : value;
|
|
47848
|
-
if (decoded !== value) add(decoded, from, from + value.length);
|
|
47849
|
-
else for (let i = 0; i < value.length; i++) add(value[i], from + i, from + i + 1);
|
|
47850
|
-
}
|
|
47851
|
-
}
|
|
47852
|
-
const start = range?.from ?? text3.indexOf(original);
|
|
47853
|
-
if (start < 0 || text3.slice(start, range?.to ?? start + original.length) !== original || !range && text3.indexOf(original, start + 1) !== -1) {
|
|
47854
|
-
throw new Error("\u9009\u533A\u5DF2\u53D8\u5316\u6216\u65E0\u6CD5\u5B9A\u4F4D\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u6B63\u6587");
|
|
47855
|
-
}
|
|
47856
|
-
let position = start;
|
|
47857
|
-
const fragments = original.split("\n").flatMap((line, index) => {
|
|
47858
|
-
const spans = offsets.slice(position, position + line.length);
|
|
47859
|
-
position += line.length + 1;
|
|
47860
|
-
return line.trim() ? [{ id: index + 1, text: line, spans }] : [];
|
|
47861
|
-
});
|
|
47862
|
-
return {
|
|
47863
|
-
fragments: fragments.map(({ id: id2, text: text4 }) => ({ id: id2, text: text4 })),
|
|
47864
|
-
patches: (replacement) => fragments.flatMap(({ id: id2, text: line, spans }) => {
|
|
47865
|
-
const value = replacement.get(id2);
|
|
47866
|
-
if (value === void 0) return [];
|
|
47867
|
-
const revised = value.trim() ? line.slice(0, line.length - line.trimStart().length) + value.trim() + line.slice(line.trimEnd().length) : "";
|
|
47868
|
-
if (line === revised) return [];
|
|
47869
|
-
let prefix2 = 0;
|
|
47870
|
-
while (prefix2 < line.length && line[prefix2] === revised[prefix2]) prefix2++;
|
|
47871
|
-
let suffix = 0;
|
|
47872
|
-
while (suffix < line.length - prefix2 && suffix < revised.length - prefix2 && line[line.length - 1 - suffix] === revised[revised.length - 1 - suffix]) suffix++;
|
|
47873
|
-
const middle = spans.slice(prefix2, line.length - suffix);
|
|
47874
|
-
const inserted = escapeProse(revised.slice(prefix2, revised.length - suffix));
|
|
47875
|
-
if (!middle.length) {
|
|
47876
|
-
const at = spans[prefix2]?.from ?? spans.at(-1).to;
|
|
47877
|
-
return [{ from: at, to: at, value: inserted }];
|
|
47878
|
-
}
|
|
47879
|
-
return middle.map((span, i) => ({ ...span, value: i === 0 ? inserted : "" }));
|
|
47880
|
-
})
|
|
47881
|
-
};
|
|
47882
|
-
}
|
|
47883
|
-
function applyProsePatches(html, patches) {
|
|
47884
|
-
let end = html.length;
|
|
47885
|
-
for (const patch3 of patches.sort((a, b2) => b2.from - a.from)) {
|
|
47886
|
-
if (patch3.to > end || patch3.from === end && patch3.from === patch3.to) {
|
|
47887
|
-
throw new Error("\u5C40\u90E8\u4FEE\u6539\u8303\u56F4\u91CD\u53E0\uFF0C\u8BF7\u5408\u5E76\u540E\u91CD\u8BD5");
|
|
47888
|
-
}
|
|
47889
|
-
html = html.slice(0, patch3.from) + patch3.value + html.slice(patch3.to);
|
|
47890
|
-
end = patch3.from;
|
|
47891
|
-
}
|
|
47892
|
-
return html;
|
|
47893
|
-
}
|
|
47894
|
-
function editProse(html, edits) {
|
|
47895
|
-
const patches = edits.flatMap((edit) => {
|
|
47896
|
-
if (/[\r\n\u2028\u2029]/.test(edit.original) || /[\r\n\u2028\u2029]/.test(edit.replacement)) {
|
|
47897
|
-
throw new Error("\u4FEE\u8BA2\u672A\u80FD\u4FDD\u7559\u539F\u6765\u7684\u6BB5\u843D\u7ED3\u6784\uFF0C\u8BF7\u91CD\u8BD5\u6216\u7F29\u5C0F\u9009\u533A");
|
|
47898
|
-
}
|
|
47899
|
-
return prepareProseEdit(html, edit.original).patches(/* @__PURE__ */ new Map([[1, edit.replacement]]));
|
|
47900
|
-
});
|
|
47901
|
-
return applyProsePatches(html, patches);
|
|
47902
|
-
}
|
|
47903
|
-
|
|
47904
48373
|
// src/yanfield/lib/ai/agent/prose.ts
|
|
47905
48374
|
function proseEditor(novel, request, config2, run2, workspace, complete, budget, previous, signal) {
|
|
47906
48375
|
const appendBases = /* @__PURE__ */ new Map();
|
|
@@ -48082,6 +48551,7 @@ function proseEditor(novel, request, config2, run2, workspace, complete, budget,
|
|
|
48082
48551
|
}
|
|
48083
48552
|
if (mode === "append") appendBases.set(change.id, appendBase);
|
|
48084
48553
|
workspace.chapterPages.delete(change.id);
|
|
48554
|
+
if (actualId) workspace.chapterPages.delete(actualId);
|
|
48085
48555
|
run2.preview = "";
|
|
48086
48556
|
return {
|
|
48087
48557
|
changeId: change.id,
|
|
@@ -48127,6 +48597,7 @@ function openWorkspace(novel, request, config2, run2, prior) {
|
|
|
48127
48597
|
const observed = /* @__PURE__ */ new Map();
|
|
48128
48598
|
const materials = /* @__PURE__ */ new Map();
|
|
48129
48599
|
const chapterPages = /* @__PURE__ */ new Map();
|
|
48600
|
+
const readBodies = /* @__PURE__ */ new Map();
|
|
48130
48601
|
const visibleKinds = {
|
|
48131
48602
|
character: config2.includeCharacters,
|
|
48132
48603
|
world: config2.includeWorld,
|
|
@@ -48145,6 +48616,16 @@ function openWorkspace(novel, request, config2, run2, prior) {
|
|
|
48145
48616
|
function candidate(kind, id2) {
|
|
48146
48617
|
return run2.changes.find((change) => change.id === id2 && change.kind === kind && change.state === "pending" && !isChapterOperation(change)) ?? prior?.changes.find((change) => change.id === id2 && change.kind === kind && change.state === "pending" && !isChapterOperation(change));
|
|
48147
48618
|
}
|
|
48619
|
+
function chapterDraft(id2) {
|
|
48620
|
+
const batchEntry = run2.changes.find((change) => change.state === "pending" && change.chapterBatch?.entries.some((entry) => entry.before.id === id2))?.chapterBatch?.entries.find((entry) => entry.before.id === id2);
|
|
48621
|
+
const prose = run2.changes.find((change) => change.kind === "chapter" && change.targetId === id2 && change.state === "pending" && !isChapterOperation(change) && !change.op && typeof change.after.content === "string");
|
|
48622
|
+
return batchEntry ? { ...batchEntry.after, pendingBatch: true } : prose ? { ...prose.after, pendingProse: true } : void 0;
|
|
48623
|
+
}
|
|
48624
|
+
function reviewedChapterBody(id2) {
|
|
48625
|
+
const current = String(chapterDraft(id2)?.content ?? observed.get(`chapter:${id2}`)?.content ?? "");
|
|
48626
|
+
const read2 = readBodies.get(id2);
|
|
48627
|
+
return read2?.content === current && (chapterPages.get(id2) ?? -1) >= current.length ? current : void 0;
|
|
48628
|
+
}
|
|
48148
48629
|
function read(kind, id2) {
|
|
48149
48630
|
permitted(kind, id2);
|
|
48150
48631
|
const draft = candidate(kind, id2);
|
|
@@ -48157,16 +48638,13 @@ function openWorkspace(novel, request, config2, run2, prior) {
|
|
|
48157
48638
|
observed.set(`blueprint:${id2}`, null);
|
|
48158
48639
|
return null;
|
|
48159
48640
|
}
|
|
48160
|
-
if (kind === "blueprint" && run2.changes.some((change) => change.id === id2 && change.kind === "chapter" && !change.targetId && change.state === "pending")) {
|
|
48161
|
-
observed.set(`blueprint:${id2}`, null);
|
|
48162
|
-
return null;
|
|
48163
|
-
}
|
|
48164
48641
|
const explicit = mentioned(kind, id2);
|
|
48165
48642
|
const saved = visibleEntity(kind, id2, novel.id, chapterIndex, explicit);
|
|
48166
48643
|
observed.set(`${kind}:${id2}`, saved);
|
|
48167
48644
|
if (!saved) return null;
|
|
48168
48645
|
const snapshot = request.snapshot;
|
|
48169
|
-
const
|
|
48646
|
+
const pending = kind === "chapter" ? chapterDraft(id2) : void 0;
|
|
48647
|
+
const row = pending ? { ...saved, ...pending } : snapshot?.id === id2 && snapshot.kind === kind ? { ...saved, ...Object.fromEntries(Object.entries(snapshot.fields).filter(([key]) => Object.hasOwn(patchSchemas[kind].shape, key))) } : saved;
|
|
48170
48648
|
if (!run2.references.some((reference) => reference.kind === kind && reference.id === id2)) {
|
|
48171
48649
|
run2.references.push({ kind, id: id2, title: String(row.title || row.name || ENTITY_LABEL[kind]) });
|
|
48172
48650
|
}
|
|
@@ -48244,8 +48722,27 @@ function openWorkspace(novel, request, config2, run2, prior) {
|
|
|
48244
48722
|
...kind === "chapter" && !field ? metadata : { field: key, fields: Object.keys(row) },
|
|
48245
48723
|
content
|
|
48246
48724
|
}, offset, limit);
|
|
48247
|
-
if (kind === "chapter" && (!field || field === "content")
|
|
48248
|
-
|
|
48725
|
+
if (kind === "chapter" && (!field || field === "content")) {
|
|
48726
|
+
const previous = readBodies.get(id2);
|
|
48727
|
+
const ranges = previous?.content === content && chapterPages.has(id2) ? previous.ranges : [];
|
|
48728
|
+
const start = Number(page.contentOffset);
|
|
48729
|
+
const ordered = [...ranges, [start, start + String(page.content).length]].sort((a, b2) => a[0] - b2[0]);
|
|
48730
|
+
const joined = [];
|
|
48731
|
+
for (const [from, to] of ordered) {
|
|
48732
|
+
const last = joined.at(-1);
|
|
48733
|
+
if (last && from <= last[1]) last[1] = Math.max(last[1], to);
|
|
48734
|
+
else joined.push([from, to]);
|
|
48735
|
+
}
|
|
48736
|
+
const readThrough = joined[0]?.[0] === 0 ? joined[0][1] : 0;
|
|
48737
|
+
readBodies.set(id2, { content, ranges: joined });
|
|
48738
|
+
chapterPages.set(id2, readThrough);
|
|
48739
|
+
if (readThrough < content.length) {
|
|
48740
|
+
page.nextOffset = readThrough;
|
|
48741
|
+
page.truncated = true;
|
|
48742
|
+
} else {
|
|
48743
|
+
page.nextOffset = null;
|
|
48744
|
+
page.truncated = false;
|
|
48745
|
+
}
|
|
48249
48746
|
}
|
|
48250
48747
|
return page;
|
|
48251
48748
|
}
|
|
@@ -48254,7 +48751,7 @@ function openWorkspace(novel, request, config2, run2, prior) {
|
|
|
48254
48751
|
if (kind === "volume-outline") return getVolume(id2)?.title ?? "";
|
|
48255
48752
|
return kind === "outline" ? novel.title : "";
|
|
48256
48753
|
}
|
|
48257
|
-
return { outlineTitle, chapterIndex, chapters, candidate, observed, materials, chapterPages, permitted, mentioned, read, readPage, search: search2, cards: cards2 };
|
|
48754
|
+
return { outlineTitle, chapterIndex, chapters, candidate, observed, materials, chapterPages, reviewedChapterBody, permitted, mentioned, read, readPage, search: search2, cards: cards2 };
|
|
48258
48755
|
}
|
|
48259
48756
|
|
|
48260
48757
|
// src/yanfield/lib/ai/agent/run.ts
|
|
@@ -48940,6 +49437,9 @@ var referenceObjects = /* @__PURE__ */ new Set([
|
|
|
48940
49437
|
"chapterSplit",
|
|
48941
49438
|
"chapterDirectory",
|
|
48942
49439
|
"chapterPair",
|
|
49440
|
+
"chapterBatch",
|
|
49441
|
+
"entries",
|
|
49442
|
+
"duplicateIn",
|
|
48943
49443
|
"second",
|
|
48944
49444
|
"existing",
|
|
48945
49445
|
"orderBefore",
|
|
@@ -48956,6 +49456,9 @@ function remapLinks(value, ids) {
|
|
|
48956
49456
|
}
|
|
48957
49457
|
function restoreAgentRun(value, ids) {
|
|
48958
49458
|
const run2 = remapLinks(value, ids);
|
|
49459
|
+
for (const { chapterBatch } of run2.changes) {
|
|
49460
|
+
if (chapterBatch) chapterBatch.titles = Object.fromEntries(Object.entries(chapterBatch.titles).map(([id2, title]) => [remapId(id2, ids), title]));
|
|
49461
|
+
}
|
|
48959
49462
|
if (run2.linkTitles && ids.size) {
|
|
48960
49463
|
run2.linkTitles = Object.fromEntries(Object.entries(run2.linkTitles).map(([key, title]) => {
|
|
48961
49464
|
const colon = key.indexOf(":") + 1;
|
|
@@ -49052,6 +49555,7 @@ var tables = [
|
|
|
49052
49555
|
"novels",
|
|
49053
49556
|
"volumes",
|
|
49054
49557
|
"chapters",
|
|
49558
|
+
"chapter_versions",
|
|
49055
49559
|
"novel_outlines",
|
|
49056
49560
|
"volume_outlines",
|
|
49057
49561
|
"chapter_blueprints",
|
|
@@ -49135,6 +49639,7 @@ var scopedLinks = [
|
|
|
49135
49639
|
["chapters", "volume_id", "volumes"],
|
|
49136
49640
|
["volume_outlines", "volume_id", "volumes"],
|
|
49137
49641
|
["chapter_blueprints", "chapter_id", "chapters"],
|
|
49642
|
+
["chapter_versions", "chapter_id", "chapters"],
|
|
49138
49643
|
["world_settings", "parent_id", "world_settings"],
|
|
49139
49644
|
["locations", "parent_id", "locations"],
|
|
49140
49645
|
["story_archives", "chapter_id", "chapters"],
|
|
@@ -49591,8 +50096,6 @@ var GET8 = handle(async (_request, { params }) => {
|
|
|
49591
50096
|
return ok(chapter);
|
|
49592
50097
|
});
|
|
49593
50098
|
var PATCH3 = handle(async (request, { params }) => {
|
|
49594
|
-
const current = getChapter(params.id);
|
|
49595
|
-
if (!current) return notFound("\u7AE0\u8282\u4E0D\u5B58\u5728");
|
|
49596
50099
|
const body = await readBody(request);
|
|
49597
50100
|
const patch3 = pickFields(body, CHAPTER_FIELDS);
|
|
49598
50101
|
const status = pickEnum(body, "status", CHAPTER_STATUSES, "\u7AE0\u8282\u72B6\u6001");
|
|
@@ -49607,12 +50110,19 @@ var PATCH3 = handle(async (request, { params }) => {
|
|
|
49607
50110
|
} else if (patch3.wordCount !== void 0) {
|
|
49608
50111
|
patch3.wordCount = Math.max(0, Math.round(patch3.wordCount));
|
|
49609
50112
|
}
|
|
49610
|
-
|
|
49611
|
-
|
|
49612
|
-
|
|
49613
|
-
|
|
49614
|
-
|
|
49615
|
-
|
|
50113
|
+
return tx(() => {
|
|
50114
|
+
const current = getChapter(params.id);
|
|
50115
|
+
if (!current) return notFound("\u7AE0\u8282\u4E0D\u5B58\u5728");
|
|
50116
|
+
if (body.expectedUpdatedAt !== void 0 && body.expectedUpdatedAt !== current.updatedAt) {
|
|
50117
|
+
return bad("\u7AE0\u8282\u5DF2\u6709\u65B0\u4FEE\u6539\u3002\u8BF7\u590D\u5236\u9700\u8981\u4FDD\u7559\u7684\u5185\u5BB9\uFF0C\u518D\u6253\u5F00\u5DF2\u4FDD\u5B58\u7248\u672C\u5408\u5E76\u3002", 409);
|
|
50118
|
+
}
|
|
50119
|
+
const next = updateChapter(params.id, patch3);
|
|
50120
|
+
if (typeof patch3.content === "string" && patch3.content !== current.content) {
|
|
50121
|
+
markArchiveStale(params.id);
|
|
50122
|
+
markArchivesStaleAfter(current.novelId, current.orderIndex);
|
|
50123
|
+
}
|
|
50124
|
+
return ok(next);
|
|
50125
|
+
});
|
|
49616
50126
|
});
|
|
49617
50127
|
var DELETE2 = handle(async (_request, { params }) => {
|
|
49618
50128
|
if (!getChapter(params.id)) return notFound("\u7AE0\u8282\u4E0D\u5B58\u5728");
|
|
@@ -49620,23 +50130,64 @@ var DELETE2 = handle(async (_request, { params }) => {
|
|
|
49620
50130
|
return ok({ ok: true });
|
|
49621
50131
|
});
|
|
49622
50132
|
|
|
49623
|
-
// src/yanfield/app/api/chapters/route.ts
|
|
50133
|
+
// src/yanfield/app/api/chapters/[id]/versions/[versionId]/route.ts
|
|
49624
50134
|
var route_exports18 = {};
|
|
49625
50135
|
__export(route_exports18, {
|
|
50136
|
+
DELETE: () => DELETE3,
|
|
49626
50137
|
GET: () => GET9,
|
|
49627
|
-
|
|
50138
|
+
PATCH: () => PATCH4,
|
|
49628
50139
|
dynamic: () => dynamic15,
|
|
49629
50140
|
runtime: () => runtime16
|
|
49630
50141
|
});
|
|
49631
50142
|
var runtime16 = "nodejs";
|
|
49632
50143
|
var dynamic15 = "force-dynamic";
|
|
50144
|
+
var GET9 = handle(
|
|
50145
|
+
(_request, { params }) => ok(getChapterVersion(params.id, params.versionId))
|
|
50146
|
+
);
|
|
50147
|
+
var PATCH4 = handle(async (request, { params }) => {
|
|
50148
|
+
const body = await readBody(request);
|
|
50149
|
+
return ok(restoreChapterVersion(params.id, params.versionId, requireString(body, "expectedUpdatedAt", "expectedUpdatedAt")));
|
|
50150
|
+
});
|
|
50151
|
+
var DELETE3 = handle((_request, { params }) => {
|
|
50152
|
+
deleteChapterVersion(params.id, params.versionId);
|
|
50153
|
+
return ok({ ok: true });
|
|
50154
|
+
});
|
|
50155
|
+
|
|
50156
|
+
// src/yanfield/app/api/chapters/[id]/versions/route.ts
|
|
50157
|
+
var route_exports19 = {};
|
|
50158
|
+
__export(route_exports19, {
|
|
50159
|
+
GET: () => GET10,
|
|
50160
|
+
POST: () => POST12,
|
|
50161
|
+
dynamic: () => dynamic16,
|
|
50162
|
+
runtime: () => runtime17
|
|
50163
|
+
});
|
|
50164
|
+
var runtime17 = "nodejs";
|
|
50165
|
+
var dynamic16 = "force-dynamic";
|
|
50166
|
+
var GET10 = handle(
|
|
50167
|
+
(_request, { params }) => ok({ items: listChapterVersions(params.id) })
|
|
50168
|
+
);
|
|
50169
|
+
var POST12 = handle(async (request, { params }) => {
|
|
50170
|
+
const body = await readBody(request);
|
|
50171
|
+
return ok(createChapterVersion(params.id, requireString(body, "expectedUpdatedAt", "expectedUpdatedAt")), { status: 201 });
|
|
50172
|
+
});
|
|
50173
|
+
|
|
50174
|
+
// src/yanfield/app/api/chapters/route.ts
|
|
50175
|
+
var route_exports20 = {};
|
|
50176
|
+
__export(route_exports20, {
|
|
50177
|
+
GET: () => GET11,
|
|
50178
|
+
POST: () => POST13,
|
|
50179
|
+
dynamic: () => dynamic17,
|
|
50180
|
+
runtime: () => runtime18
|
|
50181
|
+
});
|
|
50182
|
+
var runtime18 = "nodejs";
|
|
50183
|
+
var dynamic17 = "force-dynamic";
|
|
49633
50184
|
var CHAPTER_FIELDS2 = {
|
|
49634
50185
|
title: "str",
|
|
49635
50186
|
content: "str",
|
|
49636
50187
|
volumeId: "str|null",
|
|
49637
50188
|
orderIndex: "num"
|
|
49638
50189
|
};
|
|
49639
|
-
var
|
|
50190
|
+
var GET11 = handle(async (request) => {
|
|
49640
50191
|
const novelId = requireQueryParam(request, "novelId", "novelId");
|
|
49641
50192
|
if (!getNovel(novelId)) return ok({ items: [] });
|
|
49642
50193
|
let items = listChapters(novelId, queryParam(request, "view") !== "summary");
|
|
@@ -49644,7 +50195,7 @@ var GET9 = handle(async (request) => {
|
|
|
49644
50195
|
if (volumeId) items = items.filter((chapter) => chapter.volumeId === volumeId);
|
|
49645
50196
|
return ok({ items });
|
|
49646
50197
|
});
|
|
49647
|
-
var
|
|
50198
|
+
var POST13 = handle(async (request) => {
|
|
49648
50199
|
const body = await readBody(request);
|
|
49649
50200
|
const novelId = requireString(body, "novelId", "novelId");
|
|
49650
50201
|
if (!getNovel(novelId)) return notFound("\u4F5C\u54C1\u4E0D\u5B58\u5728");
|
|
@@ -49665,16 +50216,16 @@ var POST12 = handle(async (request) => {
|
|
|
49665
50216
|
});
|
|
49666
50217
|
|
|
49667
50218
|
// src/yanfield/app/api/characters/[id]/route.ts
|
|
49668
|
-
var
|
|
49669
|
-
__export(
|
|
49670
|
-
DELETE: () =>
|
|
49671
|
-
GET: () =>
|
|
49672
|
-
PATCH: () =>
|
|
49673
|
-
dynamic: () =>
|
|
49674
|
-
runtime: () =>
|
|
50219
|
+
var route_exports21 = {};
|
|
50220
|
+
__export(route_exports21, {
|
|
50221
|
+
DELETE: () => DELETE4,
|
|
50222
|
+
GET: () => GET12,
|
|
50223
|
+
PATCH: () => PATCH5,
|
|
50224
|
+
dynamic: () => dynamic18,
|
|
50225
|
+
runtime: () => runtime19
|
|
49675
50226
|
});
|
|
49676
|
-
var
|
|
49677
|
-
var
|
|
50227
|
+
var runtime19 = "nodejs";
|
|
50228
|
+
var dynamic18 = "force-dynamic";
|
|
49678
50229
|
var CHARACTER_FIELDS = {
|
|
49679
50230
|
name: "str",
|
|
49680
50231
|
aliases: "str[]",
|
|
@@ -49701,12 +50252,12 @@ function invalidRelations(value) {
|
|
|
49701
50252
|
(item) => !isObject(item) || typeof item.targetId !== "string" || typeof item.relation !== "string"
|
|
49702
50253
|
);
|
|
49703
50254
|
}
|
|
49704
|
-
var
|
|
50255
|
+
var GET12 = handle(async (_request, { params }) => {
|
|
49705
50256
|
const character = getCharacter(params.id);
|
|
49706
50257
|
if (!character) return notFound("\u89D2\u8272\u4E0D\u5B58\u5728");
|
|
49707
50258
|
return ok(character);
|
|
49708
50259
|
});
|
|
49709
|
-
var
|
|
50260
|
+
var PATCH5 = handle(async (request, { params }) => {
|
|
49710
50261
|
const current = getCharacter(params.id);
|
|
49711
50262
|
if (!current) return notFound("\u89D2\u8272\u4E0D\u5B58\u5728");
|
|
49712
50263
|
const body = await readBody(request);
|
|
@@ -49722,22 +50273,22 @@ var PATCH4 = handle(async (request, { params }) => {
|
|
|
49722
50273
|
if (Object.keys(patch3).length === 0) return bad("\u6CA1\u6709\u53EF\u66F4\u65B0\u7684\u5B57\u6BB5");
|
|
49723
50274
|
return ok(updateCharacter(params.id, patch3));
|
|
49724
50275
|
});
|
|
49725
|
-
var
|
|
50276
|
+
var DELETE4 = handle(async (_request, { params }) => {
|
|
49726
50277
|
if (!getCharacter(params.id)) return notFound("\u89D2\u8272\u4E0D\u5B58\u5728");
|
|
49727
50278
|
deleteCharacter(params.id);
|
|
49728
50279
|
return ok({ ok: true });
|
|
49729
50280
|
});
|
|
49730
50281
|
|
|
49731
50282
|
// src/yanfield/app/api/characters/route.ts
|
|
49732
|
-
var
|
|
49733
|
-
__export(
|
|
49734
|
-
GET: () =>
|
|
49735
|
-
POST: () =>
|
|
49736
|
-
dynamic: () =>
|
|
49737
|
-
runtime: () =>
|
|
50283
|
+
var route_exports22 = {};
|
|
50284
|
+
__export(route_exports22, {
|
|
50285
|
+
GET: () => GET13,
|
|
50286
|
+
POST: () => POST14,
|
|
50287
|
+
dynamic: () => dynamic19,
|
|
50288
|
+
runtime: () => runtime20
|
|
49738
50289
|
});
|
|
49739
|
-
var
|
|
49740
|
-
var
|
|
50290
|
+
var runtime20 = "nodejs";
|
|
50291
|
+
var dynamic19 = "force-dynamic";
|
|
49741
50292
|
var CHARACTER_FIELDS2 = {
|
|
49742
50293
|
name: "str",
|
|
49743
50294
|
aliases: "str[]",
|
|
@@ -49764,12 +50315,12 @@ function invalidRelations2(value) {
|
|
|
49764
50315
|
(item) => !isObject(item) || typeof item.targetId !== "string" || typeof item.relation !== "string"
|
|
49765
50316
|
);
|
|
49766
50317
|
}
|
|
49767
|
-
var
|
|
50318
|
+
var GET13 = handle(async (request) => {
|
|
49768
50319
|
const novelId = requireQueryParam(request, "novelId", "novelId");
|
|
49769
50320
|
if (!getNovel(novelId)) return ok({ items: [] });
|
|
49770
50321
|
return ok({ items: listCharacters(novelId) });
|
|
49771
50322
|
});
|
|
49772
|
-
var
|
|
50323
|
+
var POST14 = handle(async (request) => {
|
|
49773
50324
|
const body = await readBody(request);
|
|
49774
50325
|
const novelId = requireString(body, "novelId", "novelId");
|
|
49775
50326
|
if (!getNovel(novelId)) return notFound("\u4F5C\u54C1\u4E0D\u5B58\u5728");
|
|
@@ -49782,15 +50333,15 @@ var POST13 = handle(async (request) => {
|
|
|
49782
50333
|
});
|
|
49783
50334
|
|
|
49784
50335
|
// src/yanfield/app/api/chat/sessions/[id]/messages/[messageId]/route.ts
|
|
49785
|
-
var
|
|
49786
|
-
__export(
|
|
49787
|
-
DELETE: () =>
|
|
49788
|
-
dynamic: () =>
|
|
49789
|
-
runtime: () =>
|
|
50336
|
+
var route_exports23 = {};
|
|
50337
|
+
__export(route_exports23, {
|
|
50338
|
+
DELETE: () => DELETE5,
|
|
50339
|
+
dynamic: () => dynamic20,
|
|
50340
|
+
runtime: () => runtime21
|
|
49790
50341
|
});
|
|
49791
|
-
var
|
|
49792
|
-
var
|
|
49793
|
-
var
|
|
50342
|
+
var runtime21 = "nodejs";
|
|
50343
|
+
var dynamic20 = "force-dynamic";
|
|
50344
|
+
var DELETE5 = handle(async (request, { params }) => {
|
|
49794
50345
|
const session = getChatSession(params.id);
|
|
49795
50346
|
if (!session || queryParam(request, "novelId") !== session.novelId) return notFound("\u4F1A\u8BDD\u4E0D\u5B58\u5728");
|
|
49796
50347
|
if (!deleteMessage(params.id, params.messageId)) return notFound("\u6D88\u606F\u4E0D\u5B58\u5728");
|
|
@@ -49798,15 +50349,15 @@ var DELETE4 = handle(async (request, { params }) => {
|
|
|
49798
50349
|
});
|
|
49799
50350
|
|
|
49800
50351
|
// src/yanfield/app/api/chat/sessions/[id]/messages/route.ts
|
|
49801
|
-
var
|
|
49802
|
-
__export(
|
|
49803
|
-
GET: () =>
|
|
49804
|
-
POST: () =>
|
|
49805
|
-
dynamic: () =>
|
|
49806
|
-
runtime: () =>
|
|
50352
|
+
var route_exports24 = {};
|
|
50353
|
+
__export(route_exports24, {
|
|
50354
|
+
GET: () => GET14,
|
|
50355
|
+
POST: () => POST15,
|
|
50356
|
+
dynamic: () => dynamic21,
|
|
50357
|
+
runtime: () => runtime22
|
|
49807
50358
|
});
|
|
49808
|
-
var
|
|
49809
|
-
var
|
|
50359
|
+
var runtime22 = "nodejs";
|
|
50360
|
+
var dynamic21 = "force-dynamic";
|
|
49810
50361
|
var MESSAGE_FIELDS = {
|
|
49811
50362
|
content: "str",
|
|
49812
50363
|
actions: "json",
|
|
@@ -49817,7 +50368,7 @@ var MESSAGE_FIELDS = {
|
|
|
49817
50368
|
error: "str"
|
|
49818
50369
|
};
|
|
49819
50370
|
var MESSAGE_STATUSES = ["complete", "streaming", "error", "aborted"];
|
|
49820
|
-
var
|
|
50371
|
+
var GET14 = handle(async (request, { params }) => {
|
|
49821
50372
|
const session = getChatSession(params.id);
|
|
49822
50373
|
if (!session) return notFound("\u4F1A\u8BDD\u4E0D\u5B58\u5728");
|
|
49823
50374
|
if (queryParam(request, "novelId") !== session.novelId) return notFound("\u4F1A\u8BDD\u4E0D\u5B58\u5728");
|
|
@@ -49830,7 +50381,7 @@ var GET12 = handle(async (request, { params }) => {
|
|
|
49830
50381
|
if (!page) return bad("\u6D88\u606F\u5206\u9875\u6E38\u6807\u65E0\u6548");
|
|
49831
50382
|
return ok(page);
|
|
49832
50383
|
});
|
|
49833
|
-
var
|
|
50384
|
+
var POST15 = handle(async (request, { params }) => {
|
|
49834
50385
|
const body = await readBody(request);
|
|
49835
50386
|
const session = getChatSession(params.id);
|
|
49836
50387
|
if (!session || requireString(body, "novelId", "novelId") !== session.novelId) return notFound("\u4F1A\u8BDD\u4E0D\u5B58\u5728");
|
|
@@ -49849,16 +50400,16 @@ var POST14 = handle(async (request, { params }) => {
|
|
|
49849
50400
|
});
|
|
49850
50401
|
|
|
49851
50402
|
// src/yanfield/app/api/chat/sessions/[id]/route.ts
|
|
49852
|
-
var
|
|
49853
|
-
__export(
|
|
49854
|
-
DELETE: () =>
|
|
49855
|
-
GET: () =>
|
|
49856
|
-
PATCH: () =>
|
|
49857
|
-
dynamic: () =>
|
|
49858
|
-
runtime: () =>
|
|
50403
|
+
var route_exports25 = {};
|
|
50404
|
+
__export(route_exports25, {
|
|
50405
|
+
DELETE: () => DELETE6,
|
|
50406
|
+
GET: () => GET15,
|
|
50407
|
+
PATCH: () => PATCH6,
|
|
50408
|
+
dynamic: () => dynamic22,
|
|
50409
|
+
runtime: () => runtime23
|
|
49859
50410
|
});
|
|
49860
|
-
var
|
|
49861
|
-
var
|
|
50411
|
+
var runtime23 = "nodejs";
|
|
50412
|
+
var dynamic22 = "force-dynamic";
|
|
49862
50413
|
var SESSION_FIELDS = {
|
|
49863
50414
|
title: "str",
|
|
49864
50415
|
chapterId: "str|null",
|
|
@@ -49870,12 +50421,12 @@ function belongsToNovel(chapterId, novelId) {
|
|
|
49870
50421
|
const chapter = getChapter(chapterId);
|
|
49871
50422
|
return chapter !== void 0 && chapter.novelId === novelId;
|
|
49872
50423
|
}
|
|
49873
|
-
var
|
|
50424
|
+
var GET15 = handle(async (request, { params }) => {
|
|
49874
50425
|
const session = getChatSession(params.id);
|
|
49875
50426
|
if (!session || queryParam(request, "novelId") !== session.novelId) return notFound("\u4F1A\u8BDD\u4E0D\u5B58\u5728");
|
|
49876
50427
|
return ok(session);
|
|
49877
50428
|
});
|
|
49878
|
-
var
|
|
50429
|
+
var PATCH6 = handle(async (request, { params }) => {
|
|
49879
50430
|
const current = getChatSession(params.id);
|
|
49880
50431
|
if (!current) return notFound("\u4F1A\u8BDD\u4E0D\u5B58\u5728");
|
|
49881
50432
|
const body = await readBody(request);
|
|
@@ -49895,7 +50446,7 @@ var PATCH5 = handle(async (request, { params }) => {
|
|
|
49895
50446
|
if (Object.keys(patch3).length === 0) return bad("\u6CA1\u6709\u53EF\u66F4\u65B0\u7684\u5B57\u6BB5");
|
|
49896
50447
|
return ok(updateChatSession(params.id, patch3));
|
|
49897
50448
|
});
|
|
49898
|
-
var
|
|
50449
|
+
var DELETE6 = handle(async (request, { params }) => {
|
|
49899
50450
|
const session = getChatSession(params.id);
|
|
49900
50451
|
if (!session || queryParam(request, "novelId") !== session.novelId) return notFound("\u4F1A\u8BDD\u4E0D\u5B58\u5728");
|
|
49901
50452
|
deleteChatSession(params.id);
|
|
@@ -49903,15 +50454,15 @@ var DELETE5 = handle(async (request, { params }) => {
|
|
|
49903
50454
|
});
|
|
49904
50455
|
|
|
49905
50456
|
// src/yanfield/app/api/chat/sessions/route.ts
|
|
49906
|
-
var
|
|
49907
|
-
__export(
|
|
49908
|
-
GET: () =>
|
|
49909
|
-
POST: () =>
|
|
49910
|
-
dynamic: () =>
|
|
49911
|
-
runtime: () =>
|
|
50457
|
+
var route_exports26 = {};
|
|
50458
|
+
__export(route_exports26, {
|
|
50459
|
+
GET: () => GET16,
|
|
50460
|
+
POST: () => POST16,
|
|
50461
|
+
dynamic: () => dynamic23,
|
|
50462
|
+
runtime: () => runtime24
|
|
49912
50463
|
});
|
|
49913
|
-
var
|
|
49914
|
-
var
|
|
50464
|
+
var runtime24 = "nodejs";
|
|
50465
|
+
var dynamic23 = "force-dynamic";
|
|
49915
50466
|
var SESSION_FIELDS2 = {
|
|
49916
50467
|
title: "str",
|
|
49917
50468
|
chapterId: "str|null",
|
|
@@ -49924,13 +50475,13 @@ function checkChapter(novelId, chapterId) {
|
|
|
49924
50475
|
if (!chapter || chapter.novelId !== novelId) return false;
|
|
49925
50476
|
return chapterId;
|
|
49926
50477
|
}
|
|
49927
|
-
var
|
|
50478
|
+
var GET16 = handle(async (request) => {
|
|
49928
50479
|
const novelId = queryParam(request, "novelId");
|
|
49929
50480
|
if (!novelId) return bad("\u7F3A\u5C11\u67E5\u8BE2\u53C2\u6570 novelId");
|
|
49930
50481
|
if (!getNovel(novelId)) return ok({ items: [] });
|
|
49931
50482
|
return ok({ items: listChatSessions(novelId) });
|
|
49932
50483
|
});
|
|
49933
|
-
var
|
|
50484
|
+
var POST16 = handle(async (request) => {
|
|
49934
50485
|
const body = await readBody(request);
|
|
49935
50486
|
const novelId = requireString(body, "novelId", "novelId");
|
|
49936
50487
|
if (!getNovel(novelId)) return notFound("\u4F5C\u54C1\u4E0D\u5B58\u5728");
|
|
@@ -49950,11 +50501,11 @@ var POST15 = handle(async (request) => {
|
|
|
49950
50501
|
});
|
|
49951
50502
|
|
|
49952
50503
|
// src/yanfield/app/api/codex-order/route.ts
|
|
49953
|
-
var
|
|
49954
|
-
__export(
|
|
49955
|
-
GET: () =>
|
|
49956
|
-
POST: () =>
|
|
49957
|
-
runtime: () =>
|
|
50504
|
+
var route_exports27 = {};
|
|
50505
|
+
__export(route_exports27, {
|
|
50506
|
+
GET: () => GET17,
|
|
50507
|
+
POST: () => POST17,
|
|
50508
|
+
runtime: () => runtime25
|
|
49958
50509
|
});
|
|
49959
50510
|
|
|
49960
50511
|
// src/yanfield/lib/db/codex-order.ts
|
|
@@ -49993,13 +50544,13 @@ function moveCodexEntry(ids, id2, anchor2, after) {
|
|
|
49993
50544
|
}
|
|
49994
50545
|
|
|
49995
50546
|
// src/yanfield/app/api/codex-order/route.ts
|
|
49996
|
-
var
|
|
49997
|
-
var
|
|
50547
|
+
var runtime25 = "nodejs";
|
|
50548
|
+
var GET17 = handle(async (request) => {
|
|
49998
50549
|
const novelId = requireQueryParam(request, "novelId", "\u4F5C\u54C1");
|
|
49999
50550
|
if (!getNovel(novelId)) return notFound("\u4F5C\u54C1\u4E0D\u5B58\u5728");
|
|
50000
50551
|
return ok(getCodexOrder(novelId));
|
|
50001
50552
|
});
|
|
50002
|
-
var
|
|
50553
|
+
var POST17 = handle(async (request) => {
|
|
50003
50554
|
const input2 = external_exports.object({ novelId: external_exports.string(), group: external_exports.enum(CODEX_GROUPS), id: external_exports.string(), anchor: external_exports.string(), after: external_exports.boolean() }).safeParse(await readBody(request));
|
|
50004
50555
|
if (!input2.success) return bad("\u8D44\u6599\u6392\u5E8F\u53C2\u6570\u65E0\u6548");
|
|
50005
50556
|
const { novelId, group, id: id2, anchor: anchor2, after } = input2.data;
|
|
@@ -50017,15 +50568,15 @@ var POST16 = handle(async (request) => {
|
|
|
50017
50568
|
});
|
|
50018
50569
|
|
|
50019
50570
|
// src/yanfield/app/api/demo/route.ts
|
|
50020
|
-
var
|
|
50021
|
-
__export(
|
|
50022
|
-
POST: () =>
|
|
50023
|
-
dynamic: () =>
|
|
50024
|
-
runtime: () =>
|
|
50571
|
+
var route_exports28 = {};
|
|
50572
|
+
__export(route_exports28, {
|
|
50573
|
+
POST: () => POST18,
|
|
50574
|
+
dynamic: () => dynamic24,
|
|
50575
|
+
runtime: () => runtime26
|
|
50025
50576
|
});
|
|
50026
|
-
var
|
|
50027
|
-
var
|
|
50028
|
-
var
|
|
50577
|
+
var runtime26 = "nodejs";
|
|
50578
|
+
var dynamic24 = "force-dynamic";
|
|
50579
|
+
var POST18 = handle(async (request) => {
|
|
50029
50580
|
const body = await readOptionalBody(request);
|
|
50030
50581
|
const reset = body.reset === true || body.reset === "true";
|
|
50031
50582
|
if (!reset) return ok(seedDemo(), { status: 201 });
|
|
@@ -50036,11 +50587,11 @@ var POST17 = handle(async (request) => {
|
|
|
50036
50587
|
});
|
|
50037
50588
|
|
|
50038
50589
|
// src/yanfield/app/api/export/[novelId]/route.ts
|
|
50039
|
-
var
|
|
50040
|
-
__export(
|
|
50041
|
-
GET: () =>
|
|
50042
|
-
dynamic: () =>
|
|
50043
|
-
runtime: () =>
|
|
50590
|
+
var route_exports29 = {};
|
|
50591
|
+
__export(route_exports29, {
|
|
50592
|
+
GET: () => GET18,
|
|
50593
|
+
dynamic: () => dynamic25,
|
|
50594
|
+
runtime: () => runtime27
|
|
50044
50595
|
});
|
|
50045
50596
|
|
|
50046
50597
|
// src/yanfield/app/api/_lib/export.ts
|
|
@@ -50104,8 +50655,8 @@ function buildExport(input2) {
|
|
|
50104
50655
|
};
|
|
50105
50656
|
const volumeBlock = (group, level) => {
|
|
50106
50657
|
lines.push(heading(group.volume.title, level, format));
|
|
50107
|
-
const
|
|
50108
|
-
if (
|
|
50658
|
+
const summary2 = plain(group.volume.summary);
|
|
50659
|
+
if (summary2) lines.push("", format === "md" ? `> ${summary2.replace(/\n+/g, " ")}` : summary2);
|
|
50109
50660
|
lines.push("");
|
|
50110
50661
|
for (const chapter of group.chapters) chapterBlock(chapter, level + 1);
|
|
50111
50662
|
};
|
|
@@ -50170,9 +50721,9 @@ function buildExportResponse(result) {
|
|
|
50170
50721
|
}
|
|
50171
50722
|
|
|
50172
50723
|
// src/yanfield/app/api/export/[novelId]/route.ts
|
|
50173
|
-
var
|
|
50174
|
-
var
|
|
50175
|
-
var
|
|
50724
|
+
var runtime27 = "nodejs";
|
|
50725
|
+
var dynamic25 = "force-dynamic";
|
|
50726
|
+
var GET18 = handle(async (request, { params }) => {
|
|
50176
50727
|
const tree = getNovelTree(params.novelId);
|
|
50177
50728
|
if (!tree) return notFound("\u4F5C\u54C1\u4E0D\u5B58\u5728");
|
|
50178
50729
|
const formatRaw = queryParam(request, "format");
|
|
@@ -50225,16 +50776,16 @@ var GET16 = handle(async (request, { params }) => {
|
|
|
50225
50776
|
});
|
|
50226
50777
|
|
|
50227
50778
|
// src/yanfield/app/api/foreshadows/[id]/route.ts
|
|
50228
|
-
var
|
|
50229
|
-
__export(
|
|
50230
|
-
DELETE: () =>
|
|
50231
|
-
GET: () =>
|
|
50232
|
-
PATCH: () =>
|
|
50233
|
-
dynamic: () =>
|
|
50234
|
-
runtime: () =>
|
|
50779
|
+
var route_exports30 = {};
|
|
50780
|
+
__export(route_exports30, {
|
|
50781
|
+
DELETE: () => DELETE7,
|
|
50782
|
+
GET: () => GET19,
|
|
50783
|
+
PATCH: () => PATCH7,
|
|
50784
|
+
dynamic: () => dynamic26,
|
|
50785
|
+
runtime: () => runtime28
|
|
50235
50786
|
});
|
|
50236
|
-
var
|
|
50237
|
-
var
|
|
50787
|
+
var runtime28 = "nodejs";
|
|
50788
|
+
var dynamic26 = "force-dynamic";
|
|
50238
50789
|
var FORESHADOW_FIELDS = {
|
|
50239
50790
|
title: "str",
|
|
50240
50791
|
description: "str",
|
|
@@ -50255,12 +50806,12 @@ function findForeshadow(id2) {
|
|
|
50255
50806
|
}
|
|
50256
50807
|
return void 0;
|
|
50257
50808
|
}
|
|
50258
|
-
var
|
|
50809
|
+
var GET19 = handle(async (_request, { params }) => {
|
|
50259
50810
|
const foreshadow = findForeshadow(params.id);
|
|
50260
50811
|
if (!foreshadow) return notFound("\u4F0F\u7B14\u4E0D\u5B58\u5728");
|
|
50261
50812
|
return ok(foreshadow);
|
|
50262
50813
|
});
|
|
50263
|
-
var
|
|
50814
|
+
var PATCH7 = handle(async (request, { params }) => {
|
|
50264
50815
|
const current = findForeshadow(params.id);
|
|
50265
50816
|
if (!current) return notFound("\u4F0F\u7B14\u4E0D\u5B58\u5728");
|
|
50266
50817
|
const body = await readBody(request);
|
|
@@ -50277,22 +50828,22 @@ var PATCH6 = handle(async (request, { params }) => {
|
|
|
50277
50828
|
if (Object.keys(patch3).length === 0) return bad("\u6CA1\u6709\u53EF\u66F4\u65B0\u7684\u5B57\u6BB5");
|
|
50278
50829
|
return ok(updateForeshadow(params.id, patch3));
|
|
50279
50830
|
});
|
|
50280
|
-
var
|
|
50831
|
+
var DELETE7 = handle(async (_request, { params }) => {
|
|
50281
50832
|
if (!findForeshadow(params.id)) return notFound("\u4F0F\u7B14\u4E0D\u5B58\u5728");
|
|
50282
50833
|
deleteForeshadow(params.id);
|
|
50283
50834
|
return ok({ ok: true });
|
|
50284
50835
|
});
|
|
50285
50836
|
|
|
50286
50837
|
// src/yanfield/app/api/foreshadows/route.ts
|
|
50287
|
-
var
|
|
50288
|
-
__export(
|
|
50289
|
-
GET: () =>
|
|
50290
|
-
POST: () =>
|
|
50291
|
-
dynamic: () =>
|
|
50292
|
-
runtime: () =>
|
|
50838
|
+
var route_exports31 = {};
|
|
50839
|
+
__export(route_exports31, {
|
|
50840
|
+
GET: () => GET20,
|
|
50841
|
+
POST: () => POST19,
|
|
50842
|
+
dynamic: () => dynamic27,
|
|
50843
|
+
runtime: () => runtime29
|
|
50293
50844
|
});
|
|
50294
|
-
var
|
|
50295
|
-
var
|
|
50845
|
+
var runtime29 = "nodejs";
|
|
50846
|
+
var dynamic27 = "force-dynamic";
|
|
50296
50847
|
var FORESHADOW_FIELDS2 = {
|
|
50297
50848
|
title: "str",
|
|
50298
50849
|
description: "str",
|
|
@@ -50306,12 +50857,12 @@ function belongsToNovel3(chapterId, novelId) {
|
|
|
50306
50857
|
const chapter = getChapter(chapterId);
|
|
50307
50858
|
return chapter !== void 0 && chapter.novelId === novelId;
|
|
50308
50859
|
}
|
|
50309
|
-
var
|
|
50860
|
+
var GET20 = handle(async (request) => {
|
|
50310
50861
|
const novelId = requireQueryParam(request, "novelId", "novelId");
|
|
50311
50862
|
if (!getNovel(novelId)) return ok({ items: [] });
|
|
50312
50863
|
return ok({ items: listForeshadows(novelId) });
|
|
50313
50864
|
});
|
|
50314
|
-
var
|
|
50865
|
+
var POST19 = handle(async (request) => {
|
|
50315
50866
|
const body = await readBody(request);
|
|
50316
50867
|
const novelId = requireString(body, "novelId", "novelId");
|
|
50317
50868
|
if (!getNovel(novelId)) return notFound("\u4F5C\u54C1\u4E0D\u5B58\u5728");
|
|
@@ -50325,14 +50876,14 @@ var POST18 = handle(async (request) => {
|
|
|
50325
50876
|
});
|
|
50326
50877
|
|
|
50327
50878
|
// src/yanfield/app/api/import/apply/route.ts
|
|
50328
|
-
var
|
|
50329
|
-
__export(
|
|
50330
|
-
POST: () =>
|
|
50331
|
-
dynamic: () =>
|
|
50332
|
-
runtime: () =>
|
|
50879
|
+
var route_exports32 = {};
|
|
50880
|
+
__export(route_exports32, {
|
|
50881
|
+
POST: () => POST20,
|
|
50882
|
+
dynamic: () => dynamic28,
|
|
50883
|
+
runtime: () => runtime30
|
|
50333
50884
|
});
|
|
50334
|
-
var
|
|
50335
|
-
var
|
|
50885
|
+
var runtime30 = "nodejs";
|
|
50886
|
+
var dynamic28 = "force-dynamic";
|
|
50336
50887
|
function normalizeDrafts(value) {
|
|
50337
50888
|
if (!Array.isArray(value) || value.length === 0) return "chapters \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4";
|
|
50338
50889
|
if (value.length > MAX_IMPORT_CHAPTERS) {
|
|
@@ -50350,7 +50901,7 @@ function normalizeDrafts(value) {
|
|
|
50350
50901
|
if (drafts.length === 0) return "\u6CA1\u6709\u53EF\u5BFC\u5165\u7684\u7AE0\u8282\u5185\u5BB9";
|
|
50351
50902
|
return drafts;
|
|
50352
50903
|
}
|
|
50353
|
-
var
|
|
50904
|
+
var POST20 = handle(async (request) => {
|
|
50354
50905
|
const body = await readBody(request);
|
|
50355
50906
|
const novelId = requireString(body, "novelId", "novelId");
|
|
50356
50907
|
if (!getNovel(novelId)) return notFound("\u4F5C\u54C1\u4E0D\u5B58\u5728");
|
|
@@ -50367,16 +50918,16 @@ var POST19 = handle(async (request) => {
|
|
|
50367
50918
|
});
|
|
50368
50919
|
|
|
50369
50920
|
// src/yanfield/app/api/import/txt/route.ts
|
|
50370
|
-
var
|
|
50371
|
-
__export(
|
|
50372
|
-
POST: () =>
|
|
50373
|
-
dynamic: () =>
|
|
50374
|
-
runtime: () =>
|
|
50921
|
+
var route_exports33 = {};
|
|
50922
|
+
__export(route_exports33, {
|
|
50923
|
+
POST: () => POST21,
|
|
50924
|
+
dynamic: () => dynamic29,
|
|
50925
|
+
runtime: () => runtime31
|
|
50375
50926
|
});
|
|
50376
|
-
var
|
|
50377
|
-
var
|
|
50927
|
+
var runtime31 = "nodejs";
|
|
50928
|
+
var dynamic29 = "force-dynamic";
|
|
50378
50929
|
var MAX_FILE_BYTES = 20 * 1024 * 1024;
|
|
50379
|
-
var
|
|
50930
|
+
var POST21 = handle(async (request) => {
|
|
50380
50931
|
const contentType = request.headers.get("content-type") ?? "";
|
|
50381
50932
|
if (!contentType.includes("multipart/form-data")) {
|
|
50382
50933
|
return bad("\u8BF7\u4F7F\u7528 multipart/form-data \u4E0A\u4F20 txt \u6587\u4EF6\uFF08\u5B57\u6BB5\u540D file\uFF09");
|
|
@@ -50412,13 +50963,13 @@ var POST20 = handle(async (request) => {
|
|
|
50412
50963
|
});
|
|
50413
50964
|
|
|
50414
50965
|
// src/yanfield/app/api/locations/[id]/route.ts
|
|
50415
|
-
var
|
|
50416
|
-
__export(
|
|
50417
|
-
DELETE: () =>
|
|
50418
|
-
GET: () =>
|
|
50419
|
-
PATCH: () =>
|
|
50420
|
-
dynamic: () =>
|
|
50421
|
-
runtime: () =>
|
|
50966
|
+
var route_exports34 = {};
|
|
50967
|
+
__export(route_exports34, {
|
|
50968
|
+
DELETE: () => DELETE8,
|
|
50969
|
+
GET: () => GET21,
|
|
50970
|
+
PATCH: () => PATCH8,
|
|
50971
|
+
dynamic: () => dynamic30,
|
|
50972
|
+
runtime: () => runtime32
|
|
50422
50973
|
});
|
|
50423
50974
|
|
|
50424
50975
|
// src/yanfield/app/api/_lib/location-fields.ts
|
|
@@ -50442,14 +50993,14 @@ var LOCATION_FIELDS = {
|
|
|
50442
50993
|
};
|
|
50443
50994
|
|
|
50444
50995
|
// src/yanfield/app/api/locations/[id]/route.ts
|
|
50445
|
-
var
|
|
50446
|
-
var
|
|
50447
|
-
var
|
|
50996
|
+
var runtime32 = "nodejs";
|
|
50997
|
+
var dynamic30 = "force-dynamic";
|
|
50998
|
+
var GET21 = handle(async (_request, { params }) => {
|
|
50448
50999
|
const place = getLocation(params.id);
|
|
50449
51000
|
if (!place) return notFound("\u5730\u70B9\u4E0D\u5B58\u5728");
|
|
50450
51001
|
return ok(place);
|
|
50451
51002
|
});
|
|
50452
|
-
var
|
|
51003
|
+
var PATCH8 = handle(async (request, { params }) => {
|
|
50453
51004
|
const body = await readBody(request);
|
|
50454
51005
|
const current = getLocation(params.id);
|
|
50455
51006
|
if (!current) return notFound("\u5730\u70B9\u4E0D\u5B58\u5728");
|
|
@@ -50470,29 +51021,29 @@ var PATCH7 = handle(async (request, { params }) => {
|
|
|
50470
51021
|
if (Object.keys(patch3).length === 0) return bad("\u6CA1\u6709\u53EF\u66F4\u65B0\u7684\u5B57\u6BB5");
|
|
50471
51022
|
return ok(updateLocation(params.id, patch3));
|
|
50472
51023
|
});
|
|
50473
|
-
var
|
|
51024
|
+
var DELETE8 = handle(async (_request, { params }) => {
|
|
50474
51025
|
if (!getLocation(params.id)) return notFound("\u5730\u70B9\u4E0D\u5B58\u5728");
|
|
50475
51026
|
deleteLocation(params.id);
|
|
50476
51027
|
return ok({ ok: true });
|
|
50477
51028
|
});
|
|
50478
51029
|
|
|
50479
51030
|
// src/yanfield/app/api/locations/route.ts
|
|
50480
|
-
var
|
|
50481
|
-
__export(
|
|
50482
|
-
GET: () =>
|
|
50483
|
-
POST: () =>
|
|
50484
|
-
dynamic: () =>
|
|
50485
|
-
runtime: () =>
|
|
51031
|
+
var route_exports35 = {};
|
|
51032
|
+
__export(route_exports35, {
|
|
51033
|
+
GET: () => GET22,
|
|
51034
|
+
POST: () => POST22,
|
|
51035
|
+
dynamic: () => dynamic31,
|
|
51036
|
+
runtime: () => runtime33
|
|
50486
51037
|
});
|
|
50487
|
-
var
|
|
50488
|
-
var
|
|
50489
|
-
var
|
|
51038
|
+
var runtime33 = "nodejs";
|
|
51039
|
+
var dynamic31 = "force-dynamic";
|
|
51040
|
+
var GET22 = handle(async (request) => {
|
|
50490
51041
|
const novelId = queryParam(request, "novelId");
|
|
50491
51042
|
if (!novelId) return bad("\u7F3A\u5C11\u67E5\u8BE2\u53C2\u6570 novelId");
|
|
50492
51043
|
if (!getNovel(novelId)) return ok({ items: [] });
|
|
50493
51044
|
return ok({ items: listLocations(novelId) });
|
|
50494
51045
|
});
|
|
50495
|
-
var
|
|
51046
|
+
var POST22 = handle(async (request) => {
|
|
50496
51047
|
const body = await readBody(request);
|
|
50497
51048
|
const novelId = requireString(body, "novelId", "novelId");
|
|
50498
51049
|
if (!getNovel(novelId)) return notFound("\u4F5C\u54C1\u4E0D\u5B58\u5728");
|
|
@@ -50508,13 +51059,13 @@ var POST21 = handle(async (request) => {
|
|
|
50508
51059
|
});
|
|
50509
51060
|
|
|
50510
51061
|
// src/yanfield/app/api/novels/[id]/route.ts
|
|
50511
|
-
var
|
|
50512
|
-
__export(
|
|
50513
|
-
DELETE: () =>
|
|
50514
|
-
GET: () =>
|
|
50515
|
-
PATCH: () =>
|
|
50516
|
-
dynamic: () =>
|
|
50517
|
-
runtime: () =>
|
|
51062
|
+
var route_exports36 = {};
|
|
51063
|
+
__export(route_exports36, {
|
|
51064
|
+
DELETE: () => DELETE9,
|
|
51065
|
+
GET: () => GET23,
|
|
51066
|
+
PATCH: () => PATCH9,
|
|
51067
|
+
dynamic: () => dynamic32,
|
|
51068
|
+
runtime: () => runtime34
|
|
50518
51069
|
});
|
|
50519
51070
|
|
|
50520
51071
|
// src/yanfield/lib/novel-goal.ts
|
|
@@ -50524,8 +51075,8 @@ function isValidNovelWordGoal(value) {
|
|
|
50524
51075
|
}
|
|
50525
51076
|
|
|
50526
51077
|
// src/yanfield/app/api/novels/[id]/route.ts
|
|
50527
|
-
var
|
|
50528
|
-
var
|
|
51078
|
+
var runtime34 = "nodejs";
|
|
51079
|
+
var dynamic32 = "force-dynamic";
|
|
50529
51080
|
var NOVEL_FIELDS = {
|
|
50530
51081
|
title: "str",
|
|
50531
51082
|
subtitle: "str",
|
|
@@ -50540,12 +51091,12 @@ var NOVEL_FIELDS = {
|
|
|
50540
51091
|
pov: "str",
|
|
50541
51092
|
forbiddenWords: "str[]"
|
|
50542
51093
|
};
|
|
50543
|
-
var
|
|
51094
|
+
var GET23 = handle(async (_request, { params }) => {
|
|
50544
51095
|
const novel = getNovel(params.id);
|
|
50545
51096
|
if (!novel) return notFound("\u4F5C\u54C1\u4E0D\u5B58\u5728");
|
|
50546
51097
|
return ok(novel);
|
|
50547
51098
|
});
|
|
50548
|
-
var
|
|
51099
|
+
var PATCH9 = handle(async (request, { params }) => {
|
|
50549
51100
|
if (!getNovel(params.id)) return notFound("\u4F5C\u54C1\u4E0D\u5B58\u5728");
|
|
50550
51101
|
const body = await readBody(request);
|
|
50551
51102
|
const patch3 = pickFields(body, NOVEL_FIELDS);
|
|
@@ -50561,22 +51112,22 @@ var PATCH8 = handle(async (request, { params }) => {
|
|
|
50561
51112
|
if (Object.keys(patch3).length === 0) return bad("\u6CA1\u6709\u53EF\u66F4\u65B0\u7684\u5B57\u6BB5");
|
|
50562
51113
|
return ok(updateNovel(params.id, patch3));
|
|
50563
51114
|
});
|
|
50564
|
-
var
|
|
51115
|
+
var DELETE9 = handle(async (_request, { params }) => {
|
|
50565
51116
|
if (!getNovel(params.id)) return notFound("\u4F5C\u54C1\u4E0D\u5B58\u5728");
|
|
50566
51117
|
deleteNovel(params.id);
|
|
50567
51118
|
return ok({ ok: true });
|
|
50568
51119
|
});
|
|
50569
51120
|
|
|
50570
51121
|
// src/yanfield/app/api/novels/[id]/tree/route.ts
|
|
50571
|
-
var
|
|
50572
|
-
__export(
|
|
50573
|
-
GET: () =>
|
|
50574
|
-
dynamic: () =>
|
|
50575
|
-
runtime: () =>
|
|
51122
|
+
var route_exports37 = {};
|
|
51123
|
+
__export(route_exports37, {
|
|
51124
|
+
GET: () => GET24,
|
|
51125
|
+
dynamic: () => dynamic33,
|
|
51126
|
+
runtime: () => runtime35
|
|
50576
51127
|
});
|
|
50577
|
-
var
|
|
50578
|
-
var
|
|
50579
|
-
var
|
|
51128
|
+
var runtime35 = "nodejs";
|
|
51129
|
+
var dynamic33 = "force-dynamic";
|
|
51130
|
+
var GET24 = handle(async (_request, { params }) => {
|
|
50580
51131
|
const search2 = new URL(_request.url).searchParams;
|
|
50581
51132
|
const tree = getNovelTree(params.id, search2.get("view") !== "summary");
|
|
50582
51133
|
if (!tree) return notFound("\u4F5C\u54C1\u4E0D\u5B58\u5728");
|
|
@@ -50593,12 +51144,12 @@ var GET22 = handle(async (_request, { params }) => {
|
|
|
50593
51144
|
});
|
|
50594
51145
|
|
|
50595
51146
|
// src/yanfield/app/api/novels/route.ts
|
|
50596
|
-
var
|
|
50597
|
-
__export(
|
|
50598
|
-
GET: () =>
|
|
50599
|
-
POST: () =>
|
|
50600
|
-
dynamic: () =>
|
|
50601
|
-
runtime: () =>
|
|
51147
|
+
var route_exports38 = {};
|
|
51148
|
+
__export(route_exports38, {
|
|
51149
|
+
GET: () => GET25,
|
|
51150
|
+
POST: () => POST23,
|
|
51151
|
+
dynamic: () => dynamic34,
|
|
51152
|
+
runtime: () => runtime36
|
|
50602
51153
|
});
|
|
50603
51154
|
|
|
50604
51155
|
// src/yanfield/app/api/_lib/novels.ts
|
|
@@ -50619,8 +51170,8 @@ function listNovelSummaries() {
|
|
|
50619
51170
|
}
|
|
50620
51171
|
|
|
50621
51172
|
// src/yanfield/app/api/novels/route.ts
|
|
50622
|
-
var
|
|
50623
|
-
var
|
|
51173
|
+
var runtime36 = "nodejs";
|
|
51174
|
+
var dynamic34 = "force-dynamic";
|
|
50624
51175
|
var NOVEL_FIELDS2 = {
|
|
50625
51176
|
subtitle: "str",
|
|
50626
51177
|
author: "str",
|
|
@@ -50634,8 +51185,8 @@ var NOVEL_FIELDS2 = {
|
|
|
50634
51185
|
pov: "str",
|
|
50635
51186
|
forbiddenWords: "str[]"
|
|
50636
51187
|
};
|
|
50637
|
-
var
|
|
50638
|
-
var
|
|
51188
|
+
var GET25 = handle(async () => ok({ items: listNovelSummaries() }));
|
|
51189
|
+
var POST23 = handle(async (request) => {
|
|
50639
51190
|
const body = await readBody(request);
|
|
50640
51191
|
const title = requireString(body, "title", "\u4F5C\u54C1\u6807\u9898");
|
|
50641
51192
|
const input2 = pickFields(body, NOVEL_FIELDS2);
|
|
@@ -50648,15 +51199,15 @@ var POST22 = handle(async (request) => {
|
|
|
50648
51199
|
});
|
|
50649
51200
|
|
|
50650
51201
|
// src/yanfield/app/api/outlines/novel/[novelId]/route.ts
|
|
50651
|
-
var
|
|
50652
|
-
__export(
|
|
50653
|
-
GET: () =>
|
|
50654
|
-
PATCH: () =>
|
|
50655
|
-
dynamic: () =>
|
|
50656
|
-
runtime: () =>
|
|
51202
|
+
var route_exports39 = {};
|
|
51203
|
+
__export(route_exports39, {
|
|
51204
|
+
GET: () => GET26,
|
|
51205
|
+
PATCH: () => PATCH10,
|
|
51206
|
+
dynamic: () => dynamic35,
|
|
51207
|
+
runtime: () => runtime37
|
|
50657
51208
|
});
|
|
50658
|
-
var
|
|
50659
|
-
var
|
|
51209
|
+
var runtime37 = "nodejs";
|
|
51210
|
+
var dynamic35 = "force-dynamic";
|
|
50660
51211
|
var OUTLINE_FIELDS = {
|
|
50661
51212
|
premise: "str",
|
|
50662
51213
|
theme: "str",
|
|
@@ -50672,11 +51223,11 @@ function invalidCharacterArcs(value) {
|
|
|
50672
51223
|
if (!Array.isArray(value)) return true;
|
|
50673
51224
|
return value.some((item) => !isObject(item) || typeof item.character !== "string" || typeof item.arc !== "string");
|
|
50674
51225
|
}
|
|
50675
|
-
var
|
|
51226
|
+
var GET26 = handle(async (_request, { params }) => {
|
|
50676
51227
|
if (!getNovel(params.novelId)) return notFound("\u4F5C\u54C1\u4E0D\u5B58\u5728");
|
|
50677
51228
|
return ok(getNovelOutline(params.novelId, false));
|
|
50678
51229
|
});
|
|
50679
|
-
var
|
|
51230
|
+
var PATCH10 = handle(async (request, { params }) => {
|
|
50680
51231
|
if (!getNovel(params.novelId)) return notFound("\u4F5C\u54C1\u4E0D\u5B58\u5728");
|
|
50681
51232
|
const body = await readBody(request);
|
|
50682
51233
|
const patch3 = pickFields(body, OUTLINE_FIELDS);
|
|
@@ -50687,26 +51238,26 @@ var PATCH9 = handle(async (request, { params }) => {
|
|
|
50687
51238
|
});
|
|
50688
51239
|
|
|
50689
51240
|
// src/yanfield/app/api/outlines/volume/[volumeId]/route.ts
|
|
50690
|
-
var
|
|
50691
|
-
__export(
|
|
50692
|
-
GET: () =>
|
|
50693
|
-
PATCH: () =>
|
|
50694
|
-
dynamic: () =>
|
|
50695
|
-
runtime: () =>
|
|
51241
|
+
var route_exports40 = {};
|
|
51242
|
+
__export(route_exports40, {
|
|
51243
|
+
GET: () => GET27,
|
|
51244
|
+
PATCH: () => PATCH11,
|
|
51245
|
+
dynamic: () => dynamic36,
|
|
51246
|
+
runtime: () => runtime38
|
|
50696
51247
|
});
|
|
50697
|
-
var
|
|
50698
|
-
var
|
|
51248
|
+
var runtime38 = "nodejs";
|
|
51249
|
+
var dynamic36 = "force-dynamic";
|
|
50699
51250
|
var VOLUME_OUTLINE_FIELDS = {
|
|
50700
51251
|
summary: "str",
|
|
50701
51252
|
arcGoal: "str",
|
|
50702
51253
|
keyEvents: "str[]",
|
|
50703
51254
|
foreshadowPlan: "str[]"
|
|
50704
51255
|
};
|
|
50705
|
-
var
|
|
51256
|
+
var GET27 = handle(async (_request, { params }) => {
|
|
50706
51257
|
if (!getVolume(params.volumeId)) return notFound("\u5377\u4E0D\u5B58\u5728");
|
|
50707
51258
|
return ok(getVolumeOutline(params.volumeId, false));
|
|
50708
51259
|
});
|
|
50709
|
-
var
|
|
51260
|
+
var PATCH11 = handle(async (request, { params }) => {
|
|
50710
51261
|
if (!getVolume(params.volumeId)) return notFound("\u5377\u4E0D\u5B58\u5728");
|
|
50711
51262
|
const body = await readBody(request);
|
|
50712
51263
|
const patch3 = pickFields(body, VOLUME_OUTLINE_FIELDS);
|
|
@@ -50714,16 +51265,16 @@ var PATCH10 = handle(async (request, { params }) => {
|
|
|
50714
51265
|
});
|
|
50715
51266
|
|
|
50716
51267
|
// src/yanfield/app/api/presets/[id]/route.ts
|
|
50717
|
-
var
|
|
50718
|
-
__export(
|
|
50719
|
-
DELETE: () =>
|
|
50720
|
-
GET: () =>
|
|
50721
|
-
PATCH: () =>
|
|
50722
|
-
dynamic: () =>
|
|
50723
|
-
runtime: () =>
|
|
51268
|
+
var route_exports41 = {};
|
|
51269
|
+
__export(route_exports41, {
|
|
51270
|
+
DELETE: () => DELETE10,
|
|
51271
|
+
GET: () => GET28,
|
|
51272
|
+
PATCH: () => PATCH12,
|
|
51273
|
+
dynamic: () => dynamic37,
|
|
51274
|
+
runtime: () => runtime39
|
|
50724
51275
|
});
|
|
50725
|
-
var
|
|
50726
|
-
var
|
|
51276
|
+
var runtime39 = "nodejs";
|
|
51277
|
+
var dynamic37 = "force-dynamic";
|
|
50727
51278
|
var PRESET_FIELDS = {
|
|
50728
51279
|
novelId: "str|null",
|
|
50729
51280
|
name: "str",
|
|
@@ -50733,12 +51284,12 @@ var PRESET_FIELDS = {
|
|
|
50733
51284
|
modelRole: "str",
|
|
50734
51285
|
enabled: "bool"
|
|
50735
51286
|
};
|
|
50736
|
-
var
|
|
51287
|
+
var GET28 = handle(async (_request, { params }) => {
|
|
50737
51288
|
const preset = getPreset(params.id);
|
|
50738
51289
|
if (!preset) return notFound("\u9884\u8BBE\u4E0D\u5B58\u5728");
|
|
50739
51290
|
return ok(preset);
|
|
50740
51291
|
});
|
|
50741
|
-
var
|
|
51292
|
+
var PATCH12 = handle(async (request, { params }) => {
|
|
50742
51293
|
const current = getPreset(params.id);
|
|
50743
51294
|
if (!current) return notFound("\u9884\u8BBE\u4E0D\u5B58\u5728");
|
|
50744
51295
|
const body = await readBody(request);
|
|
@@ -50765,7 +51316,7 @@ var PATCH11 = handle(async (request, { params }) => {
|
|
|
50765
51316
|
})
|
|
50766
51317
|
);
|
|
50767
51318
|
});
|
|
50768
|
-
var
|
|
51319
|
+
var DELETE10 = handle(async (_request, { params }) => {
|
|
50769
51320
|
const preset = getPreset(params.id);
|
|
50770
51321
|
if (!preset) return notFound("\u9884\u8BBE\u4E0D\u5B58\u5728");
|
|
50771
51322
|
if (preset.isBuiltin) return bad("\u5185\u7F6E\u9884\u8BBE\u4E0D\u53EF\u5220\u9664\uFF0C\u53EF\u901A\u8FC7 PATCH \u505C\u7528");
|
|
@@ -50774,15 +51325,15 @@ var DELETE9 = handle(async (_request, { params }) => {
|
|
|
50774
51325
|
});
|
|
50775
51326
|
|
|
50776
51327
|
// src/yanfield/app/api/presets/route.ts
|
|
50777
|
-
var
|
|
50778
|
-
__export(
|
|
50779
|
-
GET: () =>
|
|
50780
|
-
POST: () =>
|
|
50781
|
-
dynamic: () =>
|
|
50782
|
-
runtime: () =>
|
|
51328
|
+
var route_exports42 = {};
|
|
51329
|
+
__export(route_exports42, {
|
|
51330
|
+
GET: () => GET29,
|
|
51331
|
+
POST: () => POST24,
|
|
51332
|
+
dynamic: () => dynamic38,
|
|
51333
|
+
runtime: () => runtime40
|
|
50783
51334
|
});
|
|
50784
|
-
var
|
|
50785
|
-
var
|
|
51335
|
+
var runtime40 = "nodejs";
|
|
51336
|
+
var dynamic38 = "force-dynamic";
|
|
50786
51337
|
var PRESET_FIELDS2 = {
|
|
50787
51338
|
novelId: "str|null",
|
|
50788
51339
|
name: "str",
|
|
@@ -50792,11 +51343,11 @@ var PRESET_FIELDS2 = {
|
|
|
50792
51343
|
modelRole: "str",
|
|
50793
51344
|
enabled: "bool"
|
|
50794
51345
|
};
|
|
50795
|
-
var
|
|
51346
|
+
var GET29 = handle(async (request) => {
|
|
50796
51347
|
const novelId = queryParam(request, "novelId");
|
|
50797
51348
|
return ok({ items: listPresets(novelId ?? void 0) });
|
|
50798
51349
|
});
|
|
50799
|
-
var
|
|
51350
|
+
var POST24 = handle(async (request) => {
|
|
50800
51351
|
const body = await readBody(request);
|
|
50801
51352
|
const name3 = requireString(body, "name", "\u9884\u8BBE\u540D\u79F0").trim();
|
|
50802
51353
|
if (!name3) return bad("\u9884\u8BBE\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A");
|
|
@@ -50815,11 +51366,11 @@ var POST23 = handle(async (request) => {
|
|
|
50815
51366
|
});
|
|
50816
51367
|
|
|
50817
51368
|
// src/yanfield/app/api/providers/[id]/balance/route.ts
|
|
50818
|
-
var
|
|
50819
|
-
__export(
|
|
50820
|
-
POST: () =>
|
|
50821
|
-
dynamic: () =>
|
|
50822
|
-
runtime: () =>
|
|
51369
|
+
var route_exports43 = {};
|
|
51370
|
+
__export(route_exports43, {
|
|
51371
|
+
POST: () => POST25,
|
|
51372
|
+
dynamic: () => dynamic39,
|
|
51373
|
+
runtime: () => runtime41
|
|
50823
51374
|
});
|
|
50824
51375
|
|
|
50825
51376
|
// src/yanfield/lib/ai/balance.ts
|
|
@@ -50912,9 +51463,9 @@ async function getProviderBalance(provider) {
|
|
|
50912
51463
|
}
|
|
50913
51464
|
|
|
50914
51465
|
// src/yanfield/app/api/providers/[id]/balance/route.ts
|
|
50915
|
-
var
|
|
50916
|
-
var
|
|
50917
|
-
var
|
|
51466
|
+
var runtime41 = "nodejs";
|
|
51467
|
+
var dynamic39 = "force-dynamic";
|
|
51468
|
+
var POST25 = handle(async (_request, { params }) => {
|
|
50918
51469
|
const provider = getProvider(params.id);
|
|
50919
51470
|
if (!provider) return notFound("\u6A21\u578B\u670D\u52A1\u4E0D\u5B58\u5728");
|
|
50920
51471
|
try {
|
|
@@ -50926,13 +51477,13 @@ var POST24 = handle(async (_request, { params }) => {
|
|
|
50926
51477
|
});
|
|
50927
51478
|
|
|
50928
51479
|
// src/yanfield/app/api/providers/[id]/route.ts
|
|
50929
|
-
var
|
|
50930
|
-
__export(
|
|
50931
|
-
DELETE: () =>
|
|
50932
|
-
GET: () =>
|
|
50933
|
-
PATCH: () =>
|
|
50934
|
-
dynamic: () =>
|
|
50935
|
-
runtime: () =>
|
|
51480
|
+
var route_exports44 = {};
|
|
51481
|
+
__export(route_exports44, {
|
|
51482
|
+
DELETE: () => DELETE11,
|
|
51483
|
+
GET: () => GET30,
|
|
51484
|
+
PATCH: () => PATCH13,
|
|
51485
|
+
dynamic: () => dynamic40,
|
|
51486
|
+
runtime: () => runtime42
|
|
50936
51487
|
});
|
|
50937
51488
|
|
|
50938
51489
|
// src/yanfield/app/api/_lib/providers.ts
|
|
@@ -50956,8 +51507,8 @@ function maskProvider(provider) {
|
|
|
50956
51507
|
}
|
|
50957
51508
|
|
|
50958
51509
|
// src/yanfield/app/api/providers/[id]/route.ts
|
|
50959
|
-
var
|
|
50960
|
-
var
|
|
51510
|
+
var runtime42 = "nodejs";
|
|
51511
|
+
var dynamic40 = "force-dynamic";
|
|
50961
51512
|
var PROVIDER_FIELDS = {
|
|
50962
51513
|
name: "str",
|
|
50963
51514
|
baseUrl: "str",
|
|
@@ -50969,12 +51520,12 @@ function invalidModels(value) {
|
|
|
50969
51520
|
if (!Array.isArray(value)) return true;
|
|
50970
51521
|
return value.some((item) => !isObject(item) || typeof item.id !== "string" || typeof item.label !== "string");
|
|
50971
51522
|
}
|
|
50972
|
-
var
|
|
51523
|
+
var GET30 = handle(async (_request, { params }) => {
|
|
50973
51524
|
const provider = getProvider(params.id);
|
|
50974
51525
|
if (!provider) return notFound("\u6A21\u578B\u670D\u52A1\u4E0D\u5B58\u5728");
|
|
50975
51526
|
return ok(maskProvider(provider));
|
|
50976
51527
|
});
|
|
50977
|
-
var
|
|
51528
|
+
var PATCH13 = handle(async (request, { params }) => {
|
|
50978
51529
|
const current = getProvider(params.id);
|
|
50979
51530
|
if (!current) return notFound("\u6A21\u578B\u670D\u52A1\u4E0D\u5B58\u5728");
|
|
50980
51531
|
const body = await readBody(request);
|
|
@@ -50995,7 +51546,7 @@ var PATCH12 = handle(async (request, { params }) => {
|
|
|
50995
51546
|
if (Object.keys(patch3).length === 0) return ok(maskProvider(current));
|
|
50996
51547
|
return ok(maskProvider(updateProvider(params.id, patch3)));
|
|
50997
51548
|
});
|
|
50998
|
-
var
|
|
51549
|
+
var DELETE11 = handle(async (_request, { params }) => {
|
|
50999
51550
|
if (!getProvider(params.id)) return notFound("\u6A21\u578B\u670D\u52A1\u4E0D\u5B58\u5728");
|
|
51000
51551
|
deleteProvider(params.id);
|
|
51001
51552
|
const settings2 = getSettings();
|
|
@@ -51017,15 +51568,15 @@ var DELETE10 = handle(async (_request, { params }) => {
|
|
|
51017
51568
|
});
|
|
51018
51569
|
|
|
51019
51570
|
// src/yanfield/app/api/providers/[id]/test/route.ts
|
|
51020
|
-
var
|
|
51021
|
-
__export(
|
|
51022
|
-
POST: () =>
|
|
51023
|
-
dynamic: () =>
|
|
51024
|
-
runtime: () =>
|
|
51571
|
+
var route_exports45 = {};
|
|
51572
|
+
__export(route_exports45, {
|
|
51573
|
+
POST: () => POST26,
|
|
51574
|
+
dynamic: () => dynamic41,
|
|
51575
|
+
runtime: () => runtime43
|
|
51025
51576
|
});
|
|
51026
|
-
var
|
|
51027
|
-
var
|
|
51028
|
-
var
|
|
51577
|
+
var runtime43 = "nodejs";
|
|
51578
|
+
var dynamic41 = "force-dynamic";
|
|
51579
|
+
var POST26 = handle(async (request, { params }) => {
|
|
51029
51580
|
const provider = getProvider(params.id);
|
|
51030
51581
|
if (!provider) return notFound("\u6A21\u578B\u670D\u52A1\u4E0D\u5B58\u5728");
|
|
51031
51582
|
const body = await readOptionalBody(request);
|
|
@@ -51035,15 +51586,15 @@ var POST25 = handle(async (request, { params }) => {
|
|
|
51035
51586
|
});
|
|
51036
51587
|
|
|
51037
51588
|
// src/yanfield/app/api/providers/harness/route.ts
|
|
51038
|
-
var
|
|
51039
|
-
__export(
|
|
51040
|
-
GET: () =>
|
|
51041
|
-
dynamic: () =>
|
|
51042
|
-
runtime: () =>
|
|
51589
|
+
var route_exports46 = {};
|
|
51590
|
+
__export(route_exports46, {
|
|
51591
|
+
GET: () => GET31,
|
|
51592
|
+
dynamic: () => dynamic42,
|
|
51593
|
+
runtime: () => runtime44
|
|
51043
51594
|
});
|
|
51044
|
-
var
|
|
51045
|
-
var
|
|
51046
|
-
var
|
|
51595
|
+
var runtime44 = "nodejs";
|
|
51596
|
+
var dynamic42 = "force-dynamic";
|
|
51597
|
+
var GET31 = handle(async () => {
|
|
51047
51598
|
const bridge2 = getHarnessBridge();
|
|
51048
51599
|
if (!bridge2) {
|
|
51049
51600
|
return ok({ routes: [], current: null, defaultModel: null });
|
|
@@ -51059,19 +51610,19 @@ var GET29 = handle(async () => {
|
|
|
51059
51610
|
});
|
|
51060
51611
|
|
|
51061
51612
|
// src/yanfield/app/api/providers/models/route.ts
|
|
51062
|
-
var
|
|
51063
|
-
__export(
|
|
51064
|
-
POST: () =>
|
|
51065
|
-
dynamic: () =>
|
|
51066
|
-
runtime: () =>
|
|
51613
|
+
var route_exports47 = {};
|
|
51614
|
+
__export(route_exports47, {
|
|
51615
|
+
POST: () => POST27,
|
|
51616
|
+
dynamic: () => dynamic43,
|
|
51617
|
+
runtime: () => runtime45
|
|
51067
51618
|
});
|
|
51068
|
-
var
|
|
51069
|
-
var
|
|
51619
|
+
var runtime45 = "nodejs";
|
|
51620
|
+
var dynamic43 = "force-dynamic";
|
|
51070
51621
|
var PROVIDER_KINDS_SET = new Set(PROVIDER_KINDS);
|
|
51071
51622
|
function str(value) {
|
|
51072
51623
|
return typeof value === "string" ? value.trim() : "";
|
|
51073
51624
|
}
|
|
51074
|
-
var
|
|
51625
|
+
var POST27 = handle(async (request) => {
|
|
51075
51626
|
const body = await request.json().catch(() => null);
|
|
51076
51627
|
if (!body) return bad("\u8BF7\u6C42\u4F53\u4E0D\u662F\u5408\u6CD5 JSON");
|
|
51077
51628
|
const providerId = str(body.providerId);
|
|
@@ -51113,12 +51664,12 @@ var POST26 = handle(async (request) => {
|
|
|
51113
51664
|
});
|
|
51114
51665
|
|
|
51115
51666
|
// src/yanfield/app/api/providers/route.ts
|
|
51116
|
-
var
|
|
51117
|
-
__export(
|
|
51118
|
-
GET: () =>
|
|
51119
|
-
POST: () =>
|
|
51120
|
-
dynamic: () =>
|
|
51121
|
-
runtime: () =>
|
|
51667
|
+
var route_exports48 = {};
|
|
51668
|
+
__export(route_exports48, {
|
|
51669
|
+
GET: () => GET32,
|
|
51670
|
+
POST: () => POST28,
|
|
51671
|
+
dynamic: () => dynamic44,
|
|
51672
|
+
runtime: () => runtime46
|
|
51122
51673
|
});
|
|
51123
51674
|
|
|
51124
51675
|
// src/yanfield/lib/ai/model-sync.ts
|
|
@@ -51159,8 +51710,8 @@ async function syncHarnessProviders() {
|
|
|
51159
51710
|
}
|
|
51160
51711
|
|
|
51161
51712
|
// src/yanfield/app/api/providers/route.ts
|
|
51162
|
-
var
|
|
51163
|
-
var
|
|
51713
|
+
var runtime46 = "nodejs";
|
|
51714
|
+
var dynamic44 = "force-dynamic";
|
|
51164
51715
|
var PROVIDER_FIELDS2 = {
|
|
51165
51716
|
name: "str",
|
|
51166
51717
|
baseUrl: "str",
|
|
@@ -51172,11 +51723,11 @@ function invalidModels2(value) {
|
|
|
51172
51723
|
if (!Array.isArray(value)) return true;
|
|
51173
51724
|
return value.some((item) => !isObject(item) || typeof item.id !== "string" || typeof item.label !== "string");
|
|
51174
51725
|
}
|
|
51175
|
-
var
|
|
51726
|
+
var GET32 = handle(async () => {
|
|
51176
51727
|
const providers = await syncHarnessProviders();
|
|
51177
51728
|
return ok({ items: providers.map(maskProvider) });
|
|
51178
51729
|
});
|
|
51179
|
-
var
|
|
51730
|
+
var POST28 = handle(async (request) => {
|
|
51180
51731
|
const body = await readBody(request);
|
|
51181
51732
|
const name3 = requireString(body, "name", "\u670D\u52A1\u540D\u79F0").trim();
|
|
51182
51733
|
if (!name3) return bad("\u670D\u52A1\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A");
|
|
@@ -51190,26 +51741,26 @@ var POST27 = handle(async (request) => {
|
|
|
51190
51741
|
});
|
|
51191
51742
|
|
|
51192
51743
|
// src/yanfield/app/api/search/route.ts
|
|
51193
|
-
var
|
|
51194
|
-
__export(
|
|
51195
|
-
GET: () =>
|
|
51196
|
-
dynamic: () =>
|
|
51197
|
-
runtime: () =>
|
|
51744
|
+
var route_exports49 = {};
|
|
51745
|
+
__export(route_exports49, {
|
|
51746
|
+
GET: () => GET33,
|
|
51747
|
+
dynamic: () => dynamic45,
|
|
51748
|
+
runtime: () => runtime47
|
|
51198
51749
|
});
|
|
51199
|
-
var
|
|
51200
|
-
var
|
|
51201
|
-
var
|
|
51750
|
+
var runtime47 = "nodejs";
|
|
51751
|
+
var dynamic45 = "force-dynamic";
|
|
51752
|
+
var GET33 = handle(async (request) => {
|
|
51202
51753
|
const q = queryParam(request, "q")?.trim() ?? "";
|
|
51203
51754
|
return ok({ items: q ? search(q) : [] });
|
|
51204
51755
|
});
|
|
51205
51756
|
|
|
51206
51757
|
// src/yanfield/app/api/settings/route.ts
|
|
51207
|
-
var
|
|
51208
|
-
__export(
|
|
51209
|
-
GET: () =>
|
|
51210
|
-
PATCH: () =>
|
|
51211
|
-
dynamic: () =>
|
|
51212
|
-
runtime: () =>
|
|
51758
|
+
var route_exports50 = {};
|
|
51759
|
+
__export(route_exports50, {
|
|
51760
|
+
GET: () => GET34,
|
|
51761
|
+
PATCH: () => PATCH14,
|
|
51762
|
+
dynamic: () => dynamic46,
|
|
51763
|
+
runtime: () => runtime48
|
|
51213
51764
|
});
|
|
51214
51765
|
|
|
51215
51766
|
// src/yanfield/app/api/_lib/settings.ts
|
|
@@ -51414,12 +51965,12 @@ function buildSettingsPatch(current, body) {
|
|
|
51414
51965
|
}
|
|
51415
51966
|
|
|
51416
51967
|
// src/yanfield/app/api/settings/route.ts
|
|
51417
|
-
var
|
|
51418
|
-
var
|
|
51419
|
-
var
|
|
51968
|
+
var runtime48 = "nodejs";
|
|
51969
|
+
var dynamic46 = "force-dynamic";
|
|
51970
|
+
var GET34 = handle(async () => {
|
|
51420
51971
|
return ok({ ...getSettings(), aiPricing: getEffectiveAiPricing() });
|
|
51421
51972
|
});
|
|
51422
|
-
var
|
|
51973
|
+
var PATCH14 = handle(async (request) => {
|
|
51423
51974
|
const body = await readBody(request);
|
|
51424
51975
|
const current = getSettings();
|
|
51425
51976
|
const patch3 = buildSettingsPatch(current, body);
|
|
@@ -51429,25 +51980,25 @@ var PATCH13 = handle(async (request) => {
|
|
|
51429
51980
|
});
|
|
51430
51981
|
|
|
51431
51982
|
// src/yanfield/app/api/stats/route.ts
|
|
51432
|
-
var
|
|
51433
|
-
__export(
|
|
51434
|
-
GET: () =>
|
|
51435
|
-
dynamic: () =>
|
|
51436
|
-
runtime: () =>
|
|
51983
|
+
var route_exports51 = {};
|
|
51984
|
+
__export(route_exports51, {
|
|
51985
|
+
GET: () => GET35,
|
|
51986
|
+
dynamic: () => dynamic47,
|
|
51987
|
+
runtime: () => runtime49
|
|
51437
51988
|
});
|
|
51438
|
-
var
|
|
51439
|
-
var
|
|
51440
|
-
var
|
|
51989
|
+
var runtime49 = "nodejs";
|
|
51990
|
+
var dynamic47 = "force-dynamic";
|
|
51991
|
+
var GET35 = handle(async () => {
|
|
51441
51992
|
return ok(getStats());
|
|
51442
51993
|
});
|
|
51443
51994
|
|
|
51444
51995
|
// src/yanfield/app/api/system/route.ts
|
|
51445
|
-
var
|
|
51446
|
-
__export(
|
|
51447
|
-
GET: () =>
|
|
51448
|
-
POST: () =>
|
|
51449
|
-
dynamic: () =>
|
|
51450
|
-
runtime: () =>
|
|
51996
|
+
var route_exports52 = {};
|
|
51997
|
+
__export(route_exports52, {
|
|
51998
|
+
GET: () => GET36,
|
|
51999
|
+
POST: () => POST29,
|
|
52000
|
+
dynamic: () => dynamic48,
|
|
52001
|
+
runtime: () => runtime50
|
|
51451
52002
|
});
|
|
51452
52003
|
import path4 from "node:path";
|
|
51453
52004
|
|
|
@@ -51466,8 +52017,8 @@ function openFolder(dir, platform = process.platform) {
|
|
|
51466
52017
|
}
|
|
51467
52018
|
|
|
51468
52019
|
// src/yanfield/app/api/system/route.ts
|
|
51469
|
-
var
|
|
51470
|
-
var
|
|
52020
|
+
var runtime50 = "nodejs";
|
|
52021
|
+
var dynamic48 = "force-dynamic";
|
|
51471
52022
|
function systemInfo() {
|
|
51472
52023
|
const dbPath = getDbPath();
|
|
51473
52024
|
return {
|
|
@@ -51478,8 +52029,8 @@ function systemInfo() {
|
|
|
51478
52029
|
customDbPath: hasCustomDbPath()
|
|
51479
52030
|
};
|
|
51480
52031
|
}
|
|
51481
|
-
var
|
|
51482
|
-
var
|
|
52032
|
+
var GET36 = handle(async () => ok(systemInfo()));
|
|
52033
|
+
var POST29 = handle(async (request) => {
|
|
51483
52034
|
if (!request.headers.get("content-type")?.includes("application/json")) {
|
|
51484
52035
|
throw new ApiError("\u9700\u8981 JSON \u8BF7\u6C42", 415);
|
|
51485
52036
|
}
|
|
@@ -51495,23 +52046,23 @@ var POST28 = handle(async (request) => {
|
|
|
51495
52046
|
});
|
|
51496
52047
|
|
|
51497
52048
|
// src/yanfield/app/api/volumes/[id]/route.ts
|
|
51498
|
-
var
|
|
51499
|
-
__export(
|
|
51500
|
-
DELETE: () =>
|
|
51501
|
-
GET: () =>
|
|
51502
|
-
PATCH: () =>
|
|
51503
|
-
dynamic: () =>
|
|
51504
|
-
runtime: () =>
|
|
52049
|
+
var route_exports53 = {};
|
|
52050
|
+
__export(route_exports53, {
|
|
52051
|
+
DELETE: () => DELETE12,
|
|
52052
|
+
GET: () => GET37,
|
|
52053
|
+
PATCH: () => PATCH15,
|
|
52054
|
+
dynamic: () => dynamic49,
|
|
52055
|
+
runtime: () => runtime51
|
|
51505
52056
|
});
|
|
51506
|
-
var
|
|
51507
|
-
var
|
|
52057
|
+
var runtime51 = "nodejs";
|
|
52058
|
+
var dynamic49 = "force-dynamic";
|
|
51508
52059
|
var VOLUME_FIELDS = { title: "str", summary: "str", orderIndex: "num" };
|
|
51509
|
-
var
|
|
52060
|
+
var GET37 = handle(async (_request, { params }) => {
|
|
51510
52061
|
const volume = getVolume(params.id);
|
|
51511
52062
|
if (!volume) return notFound("\u5377\u4E0D\u5B58\u5728");
|
|
51512
52063
|
return ok(volume);
|
|
51513
52064
|
});
|
|
51514
|
-
var
|
|
52065
|
+
var PATCH15 = handle(async (request, { params }) => {
|
|
51515
52066
|
if (!getVolume(params.id)) return notFound("\u5377\u4E0D\u5B58\u5728");
|
|
51516
52067
|
const body = await readBody(request);
|
|
51517
52068
|
const patch3 = pickFields(body, VOLUME_FIELDS);
|
|
@@ -51522,29 +52073,29 @@ var PATCH14 = handle(async (request, { params }) => {
|
|
|
51522
52073
|
if (Object.keys(patch3).length === 0) return bad("\u6CA1\u6709\u53EF\u66F4\u65B0\u7684\u5B57\u6BB5");
|
|
51523
52074
|
return ok(updateVolume(params.id, patch3));
|
|
51524
52075
|
});
|
|
51525
|
-
var
|
|
52076
|
+
var DELETE12 = handle(async (_request, { params }) => {
|
|
51526
52077
|
if (!getVolume(params.id)) return notFound("\u5377\u4E0D\u5B58\u5728");
|
|
51527
52078
|
deleteVolume(params.id);
|
|
51528
52079
|
return ok({ ok: true });
|
|
51529
52080
|
});
|
|
51530
52081
|
|
|
51531
52082
|
// src/yanfield/app/api/volumes/route.ts
|
|
51532
|
-
var
|
|
51533
|
-
__export(
|
|
51534
|
-
GET: () =>
|
|
51535
|
-
POST: () =>
|
|
51536
|
-
dynamic: () =>
|
|
51537
|
-
runtime: () =>
|
|
52083
|
+
var route_exports54 = {};
|
|
52084
|
+
__export(route_exports54, {
|
|
52085
|
+
GET: () => GET38,
|
|
52086
|
+
POST: () => POST30,
|
|
52087
|
+
dynamic: () => dynamic50,
|
|
52088
|
+
runtime: () => runtime52
|
|
51538
52089
|
});
|
|
51539
|
-
var
|
|
51540
|
-
var
|
|
52090
|
+
var runtime52 = "nodejs";
|
|
52091
|
+
var dynamic50 = "force-dynamic";
|
|
51541
52092
|
var VOLUME_FIELDS2 = { title: "str", summary: "str", orderIndex: "num" };
|
|
51542
|
-
var
|
|
52093
|
+
var GET38 = handle(async (request) => {
|
|
51543
52094
|
const novelId = requireQueryParam(request, "novelId", "novelId");
|
|
51544
52095
|
if (!getNovel(novelId)) return ok({ items: [] });
|
|
51545
52096
|
return ok({ items: listVolumes(novelId) });
|
|
51546
52097
|
});
|
|
51547
|
-
var
|
|
52098
|
+
var POST30 = handle(async (request) => {
|
|
51548
52099
|
const body = await readBody(request);
|
|
51549
52100
|
const novelId = requireString(body, "novelId", "novelId");
|
|
51550
52101
|
if (!getNovel(novelId)) return notFound("\u4F5C\u54C1\u4E0D\u5B58\u5728");
|
|
@@ -51557,16 +52108,16 @@ var POST29 = handle(async (request) => {
|
|
|
51557
52108
|
});
|
|
51558
52109
|
|
|
51559
52110
|
// src/yanfield/app/api/world/[id]/route.ts
|
|
51560
|
-
var
|
|
51561
|
-
__export(
|
|
51562
|
-
DELETE: () =>
|
|
51563
|
-
GET: () =>
|
|
51564
|
-
PATCH: () =>
|
|
51565
|
-
dynamic: () =>
|
|
51566
|
-
runtime: () =>
|
|
51567
|
-
});
|
|
51568
|
-
var
|
|
51569
|
-
var
|
|
52111
|
+
var route_exports55 = {};
|
|
52112
|
+
__export(route_exports55, {
|
|
52113
|
+
DELETE: () => DELETE13,
|
|
52114
|
+
GET: () => GET39,
|
|
52115
|
+
PATCH: () => PATCH16,
|
|
52116
|
+
dynamic: () => dynamic51,
|
|
52117
|
+
runtime: () => runtime53
|
|
52118
|
+
});
|
|
52119
|
+
var runtime53 = "nodejs";
|
|
52120
|
+
var dynamic51 = "force-dynamic";
|
|
51570
52121
|
var WORLD_FIELDS = {
|
|
51571
52122
|
title: "str",
|
|
51572
52123
|
category: "str",
|
|
@@ -51579,12 +52130,12 @@ var WORLD_FIELDS = {
|
|
|
51579
52130
|
orderIndex: "num",
|
|
51580
52131
|
pinned: "bool"
|
|
51581
52132
|
};
|
|
51582
|
-
var
|
|
52133
|
+
var GET39 = handle(async (_request, { params }) => {
|
|
51583
52134
|
const setting = getWorld(params.id);
|
|
51584
52135
|
if (!setting) return notFound("\u8BBE\u5B9A\u4E0D\u5B58\u5728");
|
|
51585
52136
|
return ok(setting);
|
|
51586
52137
|
});
|
|
51587
|
-
var
|
|
52138
|
+
var PATCH16 = handle(async (request, { params }) => {
|
|
51588
52139
|
const current = getWorld(params.id);
|
|
51589
52140
|
if (!current) return notFound("\u8BBE\u5B9A\u4E0D\u5B58\u5728");
|
|
51590
52141
|
const body = await readBody(request);
|
|
@@ -51608,22 +52159,22 @@ var PATCH15 = handle(async (request, { params }) => {
|
|
|
51608
52159
|
if (Object.keys(patch3).length === 0) return bad("\u6CA1\u6709\u53EF\u66F4\u65B0\u7684\u5B57\u6BB5");
|
|
51609
52160
|
return ok(updateWorld(params.id, patch3));
|
|
51610
52161
|
});
|
|
51611
|
-
var
|
|
52162
|
+
var DELETE13 = handle(async (_request, { params }) => {
|
|
51612
52163
|
if (!getWorld(params.id)) return notFound("\u8BBE\u5B9A\u4E0D\u5B58\u5728");
|
|
51613
52164
|
deleteWorld(params.id);
|
|
51614
52165
|
return ok({ ok: true });
|
|
51615
52166
|
});
|
|
51616
52167
|
|
|
51617
52168
|
// src/yanfield/app/api/world/route.ts
|
|
51618
|
-
var
|
|
51619
|
-
__export(
|
|
51620
|
-
GET: () =>
|
|
51621
|
-
POST: () =>
|
|
51622
|
-
dynamic: () =>
|
|
51623
|
-
runtime: () =>
|
|
51624
|
-
});
|
|
51625
|
-
var
|
|
51626
|
-
var
|
|
52169
|
+
var route_exports56 = {};
|
|
52170
|
+
__export(route_exports56, {
|
|
52171
|
+
GET: () => GET40,
|
|
52172
|
+
POST: () => POST31,
|
|
52173
|
+
dynamic: () => dynamic52,
|
|
52174
|
+
runtime: () => runtime54
|
|
52175
|
+
});
|
|
52176
|
+
var runtime54 = "nodejs";
|
|
52177
|
+
var dynamic52 = "force-dynamic";
|
|
51627
52178
|
var WORLD_FIELDS2 = {
|
|
51628
52179
|
title: "str",
|
|
51629
52180
|
category: "str",
|
|
@@ -51641,13 +52192,13 @@ function validParent(parentId, novelId) {
|
|
|
51641
52192
|
const parent = getWorld(parentId);
|
|
51642
52193
|
return parent !== void 0 && parent.novelId === novelId;
|
|
51643
52194
|
}
|
|
51644
|
-
var
|
|
52195
|
+
var GET40 = handle(async (request) => {
|
|
51645
52196
|
const novelId = queryParam(request, "novelId");
|
|
51646
52197
|
if (!novelId) return bad("\u7F3A\u5C11\u67E5\u8BE2\u53C2\u6570 novelId");
|
|
51647
52198
|
if (!getNovel(novelId)) return ok({ items: [] });
|
|
51648
52199
|
return ok({ items: listWorld(novelId) });
|
|
51649
52200
|
});
|
|
51650
|
-
var
|
|
52201
|
+
var POST31 = handle(async (request) => {
|
|
51651
52202
|
const body = await readBody(request);
|
|
51652
52203
|
const novelId = requireString(body, "novelId", "novelId");
|
|
51653
52204
|
if (!getNovel(novelId)) return notFound("\u4F5C\u54C1\u4E0D\u5B58\u5728");
|
|
@@ -51680,43 +52231,45 @@ var routes = [
|
|
|
51680
52231
|
{ pattern: "/api/chapters/:id/blueprint", handlers: route_exports15 },
|
|
51681
52232
|
{ pattern: "/api/chapters/:id/move", handlers: route_exports16 },
|
|
51682
52233
|
{ pattern: "/api/chapters/:id", handlers: route_exports17 },
|
|
51683
|
-
{ pattern: "/api/chapters", handlers: route_exports18 },
|
|
51684
|
-
{ pattern: "/api/
|
|
51685
|
-
{ pattern: "/api/
|
|
51686
|
-
{ pattern: "/api/
|
|
51687
|
-
{ pattern: "/api/
|
|
51688
|
-
{ pattern: "/api/chat/sessions/:id", handlers: route_exports23 },
|
|
51689
|
-
{ pattern: "/api/chat/sessions", handlers: route_exports24 },
|
|
51690
|
-
{ pattern: "/api/
|
|
51691
|
-
{ pattern: "/api/
|
|
51692
|
-
{ pattern: "/api/
|
|
51693
|
-
{ pattern: "/api/
|
|
51694
|
-
{ pattern: "/api/
|
|
51695
|
-
{ pattern: "/api/
|
|
51696
|
-
{ pattern: "/api/
|
|
51697
|
-
{ pattern: "/api/
|
|
51698
|
-
{ pattern: "/api/
|
|
51699
|
-
{ pattern: "/api/
|
|
51700
|
-
{ pattern: "/api/
|
|
51701
|
-
{ pattern: "/api/novels", handlers: route_exports36 },
|
|
51702
|
-
{ pattern: "/api/
|
|
51703
|
-
{ pattern: "/api/
|
|
51704
|
-
{ pattern: "/api/
|
|
51705
|
-
{ pattern: "/api/
|
|
51706
|
-
{ pattern: "/api/
|
|
51707
|
-
{ pattern: "/api/
|
|
51708
|
-
{ pattern: "/api/providers/:id/
|
|
51709
|
-
{ pattern: "/api/providers
|
|
51710
|
-
{ pattern: "/api/providers/
|
|
51711
|
-
{ pattern: "/api/providers", handlers: route_exports46 },
|
|
51712
|
-
{ pattern: "/api/
|
|
51713
|
-
{ pattern: "/api/
|
|
51714
|
-
{ pattern: "/api/
|
|
51715
|
-
{ pattern: "/api/
|
|
51716
|
-
{ pattern: "/api/
|
|
51717
|
-
{ pattern: "/api/
|
|
51718
|
-
{ pattern: "/api/
|
|
51719
|
-
{ pattern: "/api/
|
|
52234
|
+
{ pattern: "/api/chapters/:id/versions/:versionId", handlers: route_exports18 },
|
|
52235
|
+
{ pattern: "/api/chapters/:id/versions", handlers: route_exports19 },
|
|
52236
|
+
{ pattern: "/api/chapters", handlers: route_exports20 },
|
|
52237
|
+
{ pattern: "/api/characters/:id", handlers: route_exports21 },
|
|
52238
|
+
{ pattern: "/api/characters", handlers: route_exports22 },
|
|
52239
|
+
{ pattern: "/api/chat/sessions/:id/messages/:messageId", handlers: route_exports23 },
|
|
52240
|
+
{ pattern: "/api/chat/sessions/:id/messages", handlers: route_exports24 },
|
|
52241
|
+
{ pattern: "/api/chat/sessions/:id", handlers: route_exports25 },
|
|
52242
|
+
{ pattern: "/api/chat/sessions", handlers: route_exports26 },
|
|
52243
|
+
{ pattern: "/api/codex-order", handlers: route_exports27 },
|
|
52244
|
+
{ pattern: "/api/demo", handlers: route_exports28 },
|
|
52245
|
+
{ pattern: "/api/export/:novelId", handlers: route_exports29 },
|
|
52246
|
+
{ pattern: "/api/foreshadows/:id", handlers: route_exports30 },
|
|
52247
|
+
{ pattern: "/api/foreshadows", handlers: route_exports31 },
|
|
52248
|
+
{ pattern: "/api/import/apply", handlers: route_exports32 },
|
|
52249
|
+
{ pattern: "/api/import/txt", handlers: route_exports33 },
|
|
52250
|
+
{ pattern: "/api/locations/:id", handlers: route_exports34 },
|
|
52251
|
+
{ pattern: "/api/locations", handlers: route_exports35 },
|
|
52252
|
+
{ pattern: "/api/novels/:id", handlers: route_exports36 },
|
|
52253
|
+
{ pattern: "/api/novels/:id/tree", handlers: route_exports37 },
|
|
52254
|
+
{ pattern: "/api/novels", handlers: route_exports38 },
|
|
52255
|
+
{ pattern: "/api/outlines/novel/:novelId", handlers: route_exports39 },
|
|
52256
|
+
{ pattern: "/api/outlines/volume/:volumeId", handlers: route_exports40 },
|
|
52257
|
+
{ pattern: "/api/presets/:id", handlers: route_exports41 },
|
|
52258
|
+
{ pattern: "/api/presets", handlers: route_exports42 },
|
|
52259
|
+
{ pattern: "/api/providers/:id/balance", handlers: route_exports43 },
|
|
52260
|
+
{ pattern: "/api/providers/:id", handlers: route_exports44 },
|
|
52261
|
+
{ pattern: "/api/providers/:id/test", handlers: route_exports45 },
|
|
52262
|
+
{ pattern: "/api/providers/harness", handlers: route_exports46 },
|
|
52263
|
+
{ pattern: "/api/providers/models", handlers: route_exports47 },
|
|
52264
|
+
{ pattern: "/api/providers", handlers: route_exports48 },
|
|
52265
|
+
{ pattern: "/api/search", handlers: route_exports49 },
|
|
52266
|
+
{ pattern: "/api/settings", handlers: route_exports50 },
|
|
52267
|
+
{ pattern: "/api/stats", handlers: route_exports51 },
|
|
52268
|
+
{ pattern: "/api/system", handlers: route_exports52 },
|
|
52269
|
+
{ pattern: "/api/volumes/:id", handlers: route_exports53 },
|
|
52270
|
+
{ pattern: "/api/volumes", handlers: route_exports54 },
|
|
52271
|
+
{ pattern: "/api/world/:id", handlers: route_exports55 },
|
|
52272
|
+
{ pattern: "/api/world", handlers: route_exports56 }
|
|
51720
52273
|
];
|
|
51721
52274
|
|
|
51722
52275
|
// src/http.ts
|