@cloud411716/fancy-webnovel 4.30.37 → 4.30.39

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.
@@ -9,7 +9,7 @@
9
9
  * --database material_library --user root --pass root sample.jsonl
10
10
  *
11
11
  * 一条素材有基础字段 + 多层 facet:
12
- * id, kind, name, subject, tags, genres, tropes, narrative, traits, roles, relations, moods, settings, world_id, group_id, subkind, rank_order, note, source
12
+ * id, kind, name, subject, derivation, tags, genres, tropes, narrative, traits, roles, relations, moods, settings, world_id, group_id, subkind, rank_order, note, source
13
13
  *
14
14
  * 默认只追加:已存在的 id 或同 kind+name 会跳过;--update 才覆盖。
15
15
  */
@@ -22,11 +22,12 @@ import { MATERIAL_FACET_FIELDS, MATERIAL_FACET_LIMITS, MATERIAL_TAG_LIMITS, MATE
22
22
 
23
23
  const HERE = fileURLToPath(new URL('.', import.meta.url));
24
24
  const ALLOWED_FIELDS = new Set([
25
- 'id', 'kind', 'name', 'subject', 'tags', 'group_id', 'subkind', 'world_id', 'rank_order', 'note', 'source',
25
+ 'id', 'kind', 'name', 'subject', 'derivation', 'tags', 'group_id', 'subkind', 'world_id', 'rank_order', 'note', 'source',
26
26
  ...MATERIAL_FACET_FIELDS,
27
27
  ]);
28
28
  const QUALITY_TAGS = new Set(['精品', '高价值', '文笔好', '强力', '神秘']);
29
29
  const NOTE_MAX = 300;
30
+ const DERIVATION_MAX = 400;
30
31
  const SUBKIND_MAX = 40;
31
32
  const ID_RE = /^[a-z][a-z0-9_]*$/;
32
33
 
@@ -64,7 +65,7 @@ function validateRecord(raw, line, seenIds) {
64
65
 
65
66
  for (const key of Object.keys(raw)) {
66
67
  if (!ALLOWED_FIELDS.has(key)) {
67
- throw new ImportError(`不允许的字段:${key}。原子素材只允许 id/kind/name/subject/tags/各 facet/group_id/subkind/note/source`, line);
68
+ throw new ImportError(`不允许的字段:${key}。原子素材只允许 id/kind/name/subject/derivation/tags/各 facet/group_id/subkind/note/source`, line);
68
69
  }
69
70
  }
70
71
 
@@ -90,6 +91,11 @@ function validateRecord(raw, line, seenIds) {
90
91
  throw new ImportError('subject 必须是不超过 ' + MATERIAL_SUBJECT_MAX + ' 字的字符串', line);
91
92
  }
92
93
  }
94
+ if (raw.derivation !== undefined) {
95
+ if (typeof raw.derivation !== 'string' || raw.derivation.trim().length > DERIVATION_MAX) {
96
+ throw new ImportError('derivation 必须是不超过 ' + DERIVATION_MAX + ' 字的字符串', line);
97
+ }
98
+ }
93
99
  if (raw.group_id !== undefined) {
94
100
  if (typeof raw.group_id !== 'string' || !raw.group_id.trim()) {
95
101
  throw new ImportError('group_id 必须是非空字符串', line);
@@ -151,6 +157,14 @@ function validateRecord(raw, line, seenIds) {
151
157
  name: raw.name.trim(),
152
158
  tags: raw.tags.map((item) => item.trim()),
153
159
  ...(raw.subject ? { subject: raw.subject.trim() } : {}),
160
+ ...(raw.derivation ? { derivation: raw.derivation.trim() } : {}),
161
+ search_text: [
162
+ raw.kind, raw.name,
163
+ raw.subkind, raw.world_id, raw.group_id,
164
+ raw.subject, raw.derivation, raw.note,
165
+ ...(Array.isArray(raw.tags) ? raw.tags : []),
166
+ ...MATERIAL_FACET_FIELDS.flatMap((facet) => (Array.isArray(raw[facet]) ? raw[facet] : [])),
167
+ ].filter((value) => typeof value === 'string' && value.trim()).join(' '),
154
168
  ...Object.fromEntries(MATERIAL_FACET_FIELDS.map((facet) => [
155
169
  facet,
156
170
  (raw[facet] || []).map((item) => item.trim()),
@@ -390,7 +404,7 @@ function usage() {
390
404
  node import.js [连接参数] <file.jsonl>
391
405
 
392
406
  一条素材字段:
393
- id, kind, name, subject, tags, genres, tropes, narrative, traits, roles, relations, moods, settings, world_id, group_id, subkind, rank_order, note, source
407
+ id, kind, name, subject, derivation, tags, genres, tropes, narrative, traits, roles, relations, moods, settings, world_id, group_id, subkind, rank_order, note, source
394
408
 
395
409
  source:
396
410
  builtin 内置素材,kind 必须是允许列表之一
@@ -29,6 +29,7 @@ DEFINE FIELD OVERWRITE name ON material TYPE string;
29
29
  DEFINE FIELD OVERWRITE tags ON material TYPE array<string> DEFAULT [];
30
30
  DEFINE FIELD OVERWRITE subject ON material TYPE option<string>;
31
31
  DEFINE FIELD OVERWRITE derivation ON material TYPE option<string>;
32
+ DEFINE FIELD OVERWRITE search_text ON material TYPE option<string>;
32
33
  DEFINE FIELD OVERWRITE genres ON material TYPE array<string> DEFAULT [];
33
34
  DEFINE FIELD OVERWRITE tropes ON material TYPE option<array<string>>;
34
35
  DEFINE FIELD OVERWRITE narrative ON material TYPE option<array<string>>;
@@ -75,6 +76,7 @@ DEFINE INDEX IF NOT EXISTS material_name_search
75
76
  SEARCH ANALYZER material_zh
76
77
  BM25(1.2, 0.75);
77
78
 
79
+
78
80
  -- ---------------------------------------------------------------------------
79
81
  -- 抖音账号(v12)
80
82
  --
@@ -17,7 +17,7 @@ import { readSecrets, readWorkspace } from './workspace.js';
17
17
  import { rpcUrl, startServer } from './surreal-server.js';
18
18
 
19
19
  export const MATERIAL_DATABASE = 'material_library';
20
- export const MATERIAL_SCHEMA_VERSION = 15;
20
+ export const MATERIAL_SCHEMA_VERSION = 16;
21
21
 
22
22
  const SCHEMA_FILE = fileURLToPath(new URL('../docs/material-library/schema.surql', import.meta.url));
23
23
 
@@ -61,7 +61,7 @@ export async function connectMaterial(root) {
61
61
  /**
62
62
  * Ensure the material database and its schema exist. Idempotent.
63
63
  *
64
- * Schema v15 adds material.derivation; v14 changes the builtin kind catalog and adds material.world_id / rank_order; v13 adds the douyin_style table; v12 adds the douyin_account table; v11 adds the multi-layer material facets (`subject`, `tropes`, `narrative`, `traits`, `roles`, `relations`, `moods`, `settings`) and keeps the v10 douyin task tables / v9 subkind / v8 note assertion / v7 group_id / 58-kind catalog. Before applying the
64
+ * Schema v16 adds material.search_text and its full-text index; v15 adds material.derivation; v14 changes the builtin kind catalog and adds material.world_id / rank_order; v13 adds the douyin_style table; v12 adds the douyin_account table; v11 adds the multi-layer material facets (`subject`, `tropes`, `narrative`, `traits`, `roles`, `relations`, `moods`, `settings`) and keeps the v10 douyin task tables / v9 subkind / v8 note assertion / v7 group_id / 58-kind catalog. Before applying the
65
65
  * new ASSERT, rows belonging to retired kinds are removed; otherwise SurrealDB
66
66
  * refuses to overwrite the field because existing records no longer conform.
67
67
  *
@@ -99,10 +99,33 @@ export async function ensureMaterialDatabase(root) {
99
99
  }
100
100
  }
101
101
  await db.query(materialSchemaText());
102
+ // Backfill the internal full-text document for rows created before v16.
103
+ const missingSearch = await db.query("SELECT count() AS n FROM material WHERE search_text = NONE GROUP ALL;");
104
+ const missingSearchRow = Array.isArray(missingSearch) && Array.isArray(missingSearch[0]) ? missingSearch[0][0] : null;
105
+ if (missingSearchRow && Number(missingSearchRow.n) > 0) {
106
+ await db.query(`UPDATE material SET search_text = array::join(array::flatten([
107
+ kind, name,
108
+ IF subkind = NONE THEN '' ELSE subkind END,
109
+ IF world_id = NONE THEN '' ELSE world_id END,
110
+ IF group_id = NONE THEN '' ELSE group_id END,
111
+ IF subject = NONE THEN '' ELSE subject END,
112
+ IF derivation = NONE THEN '' ELSE derivation END,
113
+ IF note = NONE THEN '' ELSE note END,
114
+ IF tags = NONE THEN [] ELSE tags END,
115
+ IF genres = NONE THEN [] ELSE genres END,
116
+ IF tropes = NONE THEN [] ELSE tropes END,
117
+ IF narrative = NONE THEN [] ELSE narrative END,
118
+ IF traits = NONE THEN [] ELSE traits END,
119
+ IF roles = NONE THEN [] ELSE roles END,
120
+ IF relations = NONE THEN [] ELSE relations END,
121
+ IF moods = NONE THEN [] ELSE moods END,
122
+ IF settings = NONE THEN [] ELSE settings END
123
+ ]), ' ') WHERE search_text = NONE;`);
124
+ }
102
125
  const tableInfo = await db.query('INFO FOR TABLE material;');
103
126
  const table = Array.isArray(tableInfo) && tableInfo[0] ? tableInfo[0] : {};
104
127
  if (!table.fields || !table.fields.source || !table.fields.kind || !table.fields.name || !table.fields.tags || !table.fields.group_id || !table.fields.subkind
105
- || !table.fields.subject || !table.fields.derivation || !table.fields.genres || !table.fields.tropes || !table.fields.narrative
128
+ || !table.fields.subject || !table.fields.derivation || !table.fields.search_text || !table.fields.genres || !table.fields.tropes || !table.fields.narrative
106
129
  || !table.fields.traits || !table.fields.roles || !table.fields.relations || !table.fields.moods || !table.fields.settings || !table.fields.world_id || !table.fields.rank_order) {
107
130
  throw new Error('素材库 schema 初始化后仍未找到 material 的多层标签字段(kind/name/tags/subject/genres/tropes/narrative/traits/roles/relations/moods/settings/world_id/rank_order)。');
108
131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud411716/fancy-webnovel",
3
- "version": "4.30.37",
3
+ "version": "4.30.39",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -1638,15 +1638,6 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
1638
1638
  });
1639
1639
  if (metadataProblem) return { ok: false, detail: metadataProblem };
1640
1640
  const records = readJsonlRecords(file);
1641
- const nameFormProblem = chargingBarNameFormProblem(records, primaryStyleKey);
1642
- if (nameFormProblem) return { ok: false, detail: nameFormProblem };
1643
- const nameHighConceptProblem = chargingBarNameHighConceptProblem(records, primaryStyleKey);
1644
- const nameGroundingProblem = chargingBarNameGroundingProblem(records, primaryStyleKey);
1645
- const nameDiversityProblem = chargingBarNameDiversityProblem(records, primaryStyleKey, {
1646
- historical: rememberedNames(item),
1647
- });
1648
- const nameProblems = [nameHighConceptProblem, nameGroundingProblem, nameDiversityProblem].filter(Boolean);
1649
- if (nameProblems.length) return { ok: false, detail: nameProblems.join('\n\n') };
1650
1641
  return { ok: true, records };
1651
1642
  };
1652
1643
 
@@ -1669,11 +1660,6 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
1669
1660
  const expectedGroup = item.group_id || groupId;
1670
1661
  if (expectedGroup && record.group_id !== expectedGroup) reasons.push('group_id');
1671
1662
  if (typeof record.name !== 'string' || !record.name.trim()) reasons.push('name');
1672
- if (primaryStyleKey) {
1673
- if (chargingBarNameFormProblem([record], primaryStyleKey)) reasons.push('name-form');
1674
- if (chargingBarNameHighConceptProblem([record], primaryStyleKey)) reasons.push('name-concept');
1675
- if (chargingBarNameGroundingProblem([record], primaryStyleKey)) reasons.push('name-grounding');
1676
- }
1677
1663
  if (reasons.length) dropped.push((record.name || '未命名') + '(' + reasons.join('、') + ')');
1678
1664
  else kept.push(record);
1679
1665
  }
@@ -258,9 +258,13 @@ async function main() {
258
258
  }
259
259
  if (opts.search) {
260
260
  const term = q(opts.search);
261
- const searchable = ['tags', 'genres', 'tropes', 'narrative', 'traits', 'roles', 'relations', 'moods', 'settings'];
261
+ // Name has a full-text index; the facet arrays have normal indexes. This
262
+ // avoids a bulk ngram index over the entire 190k corpus, which is too heavy
263
+ // for the workspace SurrealDB process.
264
+ const arrayFields = ['tags', 'genres', 'tropes', 'narrative', 'traits', 'roles', 'relations', 'moods', 'settings'];
262
265
  where.push('(name @1@ ' + term
263
- + searchable.map((field) => ' OR ' + arrayContains(field, opts.search)).join('')
266
+ + ' OR subject = ' + term
267
+ + arrayFields.map((field) => ' OR ' + field + ' CONTAINS ' + term).join('')
264
268
  + ')');
265
269
  }
266
270