dsh-rp-card 1.5.4 → 1.6.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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# 更新记录
|
|
2
2
|
|
|
3
|
+
## 1.6.0
|
|
4
|
+
|
|
5
|
+
资料库 MVP 落地:可导入材料并按两套方案生成世界书条目。
|
|
6
|
+
|
|
7
|
+
- 新增 lib/library/:sources(编码判定、四类切分、来源登记)、records(条目存储、哈希保护、证据逐字校验)、budget(复杂度、A/B 两套方案、降级顺序)、mapping(条目→世界书、锚点、阶段前缀)、validate(LIB001–LIB007)、state(阶段、深度、确认、暂停恢复、用量记账)。
|
|
8
|
+
- 新增工具 card_library:status / ingest / commit / allocate / propose / approve / write / visual / pause / resume / next-batch / usage。工具不调模型,抽取由 agent 完成。
|
|
9
|
+
- 资料库规范补充:材料缺失三选项、搜索与抓取计费口径(每次约 0.005 元、失败不计费、只做估算)、先报后做、工具动作表。
|
|
10
|
+
- 新增 7 个测试文件(sources / records / budget / mapping / validate / state / tool),注入测试纳入 card_library。
|
|
11
|
+
|
|
3
12
|
## 1.5.4
|
|
4
13
|
|
|
5
14
|
资料库流程(同人 / 改编 / 参考材料)。
|
|
@@ -35,19 +35,60 @@
|
|
|
35
35
|
- 否定语境:「不要同人」「别用原作设定」不触发。
|
|
36
36
|
- 泛指:「想做点有同人感的卡」不触发,按普通原创卡处理。
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
材料缺失时的处理(给三条路,不要只问"传不传"):
|
|
39
39
|
|
|
40
40
|
```text
|
|
41
|
-
用户:做一张《XXX
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
用户:做一张《XXX》的同人卡,没材料。
|
|
42
|
+
插件:做同人卡最好有原作材料,否则容易写偏。三个办法:
|
|
43
|
+
① 你自己上传(推荐):把小说/剧本/设定集放进工作区,或直接发附件,免费且来源清楚;
|
|
44
|
+
② 我帮你找:调用搜索与网页抓取收集公开资料,按次计费,我会先报预计次数和费用;
|
|
45
|
+
③ 不做资料库,直接按原创卡做。
|
|
46
|
+
你选哪个?
|
|
46
47
|
```
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
三个分支的处理:
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
- 选 ①:等材料,走正常流程。
|
|
52
|
+
- 选 ②:先报计划与费用(见下),用户同意后抓取;材料同样走来源登记。
|
|
53
|
+
- 选 ③:取消流程,按原创卡做,不再追问,也不保留任何资料库文件。
|
|
54
|
+
|
|
55
|
+
用户先说"不传"、后来又改成"那我上传"时,直接按 ① 继续,不要重复劝。
|
|
56
|
+
|
|
57
|
+
抓取能力与计费(说法必须准确):
|
|
58
|
+
|
|
59
|
+
- 可调用的是搜索与网页抓取两个接口,二者都按**成功请求次数**计费,不按 token、也不按返回条数计费。
|
|
60
|
+
- 单价:每 1000 次成功请求 5 元,即**每次约 0.005 元**。
|
|
61
|
+
- 只有返回 200 且确实拿到内容才计费:搜索返回空结果、抓取拿不到正文、超时、报错,都不计费。
|
|
62
|
+
- `count`(返回条数)不影响单价。
|
|
63
|
+
- 速度限制按账号计算,正常串行使用不会撞限。
|
|
64
|
+
|
|
65
|
+
费用怎么向用户说明(can 与 cannot 要分清):
|
|
66
|
+
|
|
67
|
+
- **能做的**:统计本次实际发起的搜索次数与抓取次数,按每次 0.005 元算出估算值。
|
|
68
|
+
- **不能做的**:读不到用户账户账单,无法给出精确扣费金额。
|
|
69
|
+
- 所以说法固定为"**估算**",并附一句"实际以账单为准"。
|
|
70
|
+
|
|
71
|
+
汇报格式:
|
|
72
|
+
|
|
73
|
+
```text
|
|
74
|
+
本次资料收集:搜索 6 次、抓取 4 次,共 10 次成功请求。
|
|
75
|
+
按每次约 0.005 元估算,约 0.05 元;失败与空结果不计费。实际以你的账单为准。
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
抓取前的报价(先报后做,不要先抓再报):
|
|
79
|
+
|
|
80
|
+
```text
|
|
81
|
+
预计要搜 5~8 次、抓 3~5 个页面,合计 8~13 次请求,估算 0.04~0.07 元。
|
|
82
|
+
要我按这个规模抓吗?也可以只抓官方设定,次数会更少。
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
抓取规则:
|
|
86
|
+
|
|
87
|
+
- 只抓公开可访问的设定资料、百科条目、官方介绍;不抓同人小说全文。
|
|
88
|
+
- 每条材料必须登记 `url`、`retrieved_at`、`realm`(默认 `reference`,来源不明记 `unknown`)。
|
|
89
|
+
- 抓到的内容作为材料登记,同样要切分、留证据、标阶段。
|
|
90
|
+
- 超过用户同意的规模即停,先报告已花费再问是否继续。
|
|
91
|
+
- 遇到限速或失败的重试不算成功请求,不计费;但要如实说明重试过。
|
|
51
92
|
|
|
52
93
|
## 三、材料读取
|
|
53
94
|
|
|
@@ -409,6 +450,56 @@ library: {
|
|
|
409
450
|
|
|
410
451
|
---
|
|
411
452
|
|
|
453
|
+
## 十九、工具动作(card_library)
|
|
454
|
+
|
|
455
|
+
工具只做切分、校验、存储与预算,**不调模型**;抽取由你完成,结果用 commit 写入。
|
|
456
|
+
|
|
457
|
+
| 动作 | 用途 | 关键参数 |
|
|
458
|
+
|---|---|---|
|
|
459
|
+
| `status` | 看当前阶段、材料数、条目数、下一步 | — |
|
|
460
|
+
| `ingest` | 导入材料并切分,返回切分预览 | `file` 或 `text`、`id`、`kind`、`realm`、`continuity`、`phase` |
|
|
461
|
+
| `commit` | 写入带原文证据的条目,逐条校验引文 | `records`(数组) |
|
|
462
|
+
| `allocate` | 算两套取舍方案并落盘所选 | `scheme`、`startPhase`、`complexity` |
|
|
463
|
+
| `propose` | 生成方案文档给人看 | `startPhase`、`complexity` |
|
|
464
|
+
| `approve` | 记录用户选定的方案 | `scheme` = A 或 B |
|
|
465
|
+
| `write` | 生成世界书条目并跑 LIB 校验 | `scheme`、`startPhase` |
|
|
466
|
+
| `visual` | 保存视觉参考交付文档 | `visual`(数组,需 `use` 与 `note`) |
|
|
467
|
+
| `pause` / `resume` | 暂停与恢复 | — |
|
|
468
|
+
| `next-batch` | 开下一批(受上限约束) | — |
|
|
469
|
+
| `usage` | 记一次用量(同 attempt 不重复计) | `attempt_id`、`usage_kind`、`calls`、`input_tokens`、`output_tokens` |
|
|
470
|
+
|
|
471
|
+
条目字段(commit 时每条必须有):
|
|
472
|
+
|
|
473
|
+
```json
|
|
474
|
+
{
|
|
475
|
+
"id": "char-ayu",
|
|
476
|
+
"kind": "character",
|
|
477
|
+
"name": "阿雨",
|
|
478
|
+
"aliases": ["小雨"],
|
|
479
|
+
"realm": "canon",
|
|
480
|
+
"continuity": "novel-main",
|
|
481
|
+
"known_from": 0,
|
|
482
|
+
"status": "confirmed",
|
|
483
|
+
"body": "## 基本信息\n开着一间小咖啡店。",
|
|
484
|
+
"evidence": [{ "source_id": "novel-a", "unit_id": "u000001", "quote": "原文里逐字出现的一句话" }]
|
|
485
|
+
}
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
产出文件:
|
|
489
|
+
|
|
490
|
+
```text
|
|
491
|
+
.card-build/library/
|
|
492
|
+
sources/<id>.txt + .json 材料与切分结果
|
|
493
|
+
records/<id>.md 资料条目(可人工编辑)
|
|
494
|
+
index.jsonl 索引
|
|
495
|
+
plan.json 预算与分配
|
|
496
|
+
library-proposal.md 两套方案(给人看)
|
|
497
|
+
wb-entries.json 世界书条目(交给第一部分)
|
|
498
|
+
visual.json + visual-proposal.md 视觉参考(独立交付)
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
---
|
|
502
|
+
|
|
412
503
|
## 十八、分期
|
|
413
504
|
|
|
414
505
|
| 阶段 | 内容 |
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { libraryAction } from './lib/library/tool.js';
|
|
4
5
|
import {
|
|
5
6
|
ensureState, readState, writeState, markAwaiting, passPart, failPart,
|
|
6
7
|
detectChanged, assemble, mergeParts, PARTS, PLAYABLE_PARTS, PART_NAMES, lintCard, lintWorldbook,
|
|
@@ -1000,6 +1001,69 @@ export function apply(ctx) {
|
|
|
1000
1001
|
}));
|
|
1001
1002
|
});
|
|
1002
1003
|
|
|
1004
|
+
bindService(ctx, 'tools', (c, tools) => {
|
|
1005
|
+
c.effect(() => tools.register({
|
|
1006
|
+
name: 'card_library',
|
|
1007
|
+
description: '同人/改编/参考材料的资料库流程:把用户给的小说、剧本、设定集、游戏文本整理成可回查的资料库,再取舍成世界书条目。动作:status(当前阶段)→ ingest(导入材料并切分)→ commit(写入带原文证据的条目)→ allocate(算两套取舍方案)→ propose(生成方案文档给用户选)→ approve(记录用户选定)→ write(生成世界书条目并校验)→ visual(视觉参考交付)→ pause / resume / next-batch / usage。工具不调模型:切分、校验、存储由它做,抽取由你完成。',
|
|
1008
|
+
parameters: {
|
|
1009
|
+
type: 'object',
|
|
1010
|
+
properties: {
|
|
1011
|
+
action: {
|
|
1012
|
+
type: 'string',
|
|
1013
|
+
enum: ['status', 'ingest', 'commit', 'allocate', 'propose', 'approve', 'write', 'visual', 'pause', 'resume', 'next-batch', 'usage'],
|
|
1014
|
+
description: '要执行的操作',
|
|
1015
|
+
},
|
|
1016
|
+
out: { type: 'string', description: '作品目录;省略=当前会话工作区' },
|
|
1017
|
+
file: { type: 'string', description: 'ingest 时:材料文件路径(相对作品目录或绝对路径)' },
|
|
1018
|
+
text: { type: 'string', description: 'ingest 时:直接给材料正文(与 file 二选一)' },
|
|
1019
|
+
id: { type: 'string', description: '材料或条目 ID(小写字母/数字/短横线)' },
|
|
1020
|
+
kind: { type: 'string', enum: ['novel', 'screenplay', 'setting-book', 'game-script'], description: 'ingest 时:材料类型' },
|
|
1021
|
+
title: { type: 'string', description: '材料标题' },
|
|
1022
|
+
realm: { type: 'string', enum: ['canon', 'reference', 'fanon', 'unknown'], description: '来源身份' },
|
|
1023
|
+
continuity: { type: 'string', description: '世界线,如 novel-main / anime-2024' },
|
|
1024
|
+
edition: { type: 'string', description: '底本或修订版本' },
|
|
1025
|
+
phase: { type: 'number', description: '材料最早可用阶段;未知省略' },
|
|
1026
|
+
records: { type: 'array', description: 'commit 时:资料条目数组', items: { type: 'object' } },
|
|
1027
|
+
visual: { type: 'array', description: 'visual 时:视觉参考数组', items: { type: 'object' } },
|
|
1028
|
+
scheme: { type: 'string', enum: ['A', 'B'], description: '取舍方案:A 沉浸优先 / B 轻量优先' },
|
|
1029
|
+
startPhase: { type: 'number', description: '开局阶段,默认 0' },
|
|
1030
|
+
complexity: { type: 'string', enum: ['simple', 'complex'], description: '强制预算档;省略则按条目数自动判定' },
|
|
1031
|
+
attempt_id: { type: 'string', description: 'usage 时:本次尝试的唯一 ID' },
|
|
1032
|
+
batch_id: { type: 'string', description: 'usage 时:批次 ID' },
|
|
1033
|
+
usage_kind: { type: 'string', enum: ['measured', 'estimated', 'unavailable'], description: 'usage 时:用量可信度' },
|
|
1034
|
+
calls: { type: 'number', description: 'usage 时:本次调用次数' },
|
|
1035
|
+
input_tokens: { type: 'number', description: 'usage 时:输入 token' },
|
|
1036
|
+
output_tokens: { type: 'number', description: 'usage 时:输出 token' },
|
|
1037
|
+
},
|
|
1038
|
+
required: ['action'],
|
|
1039
|
+
},
|
|
1040
|
+
output: {
|
|
1041
|
+
schema: {
|
|
1042
|
+
type: 'object',
|
|
1043
|
+
properties: {
|
|
1044
|
+
ok: { type: 'boolean' },
|
|
1045
|
+
action: { type: 'string' },
|
|
1046
|
+
output: { type: 'string' },
|
|
1047
|
+
},
|
|
1048
|
+
required: ['ok', 'action', 'output'],
|
|
1049
|
+
},
|
|
1050
|
+
render: (_args, value) => [
|
|
1051
|
+
{ type: 'text', text: value && typeof value.output === 'string' ? value.output : JSON.stringify(value, null, 2) },
|
|
1052
|
+
],
|
|
1053
|
+
},
|
|
1054
|
+
execute: async (args) => {
|
|
1055
|
+
const act = args && args.action ? String(args.action) : 'status';
|
|
1056
|
+
try {
|
|
1057
|
+
const sessionCwd = await resolveCwd(pluginCtx);
|
|
1058
|
+
const result = libraryAction({ ...(args || {}), __cwd: sessionCwd || undefined });
|
|
1059
|
+
return { ok: true, action: act, output: String(result) };
|
|
1060
|
+
} catch (e) {
|
|
1061
|
+
return { ok: false, action: act, output: `错误:${e && e.message ? e.message : String(e)}` };
|
|
1062
|
+
}
|
|
1063
|
+
},
|
|
1064
|
+
}));
|
|
1065
|
+
});
|
|
1066
|
+
|
|
1003
1067
|
bindService(ctx, 'tools', (c, tools) => {
|
|
1004
1068
|
c.effect(() => tools.register({
|
|
1005
1069
|
name: 'image_asset',
|
|
@@ -1155,6 +1219,11 @@ export function apply(ctx) {
|
|
|
1155
1219
|
'- 只出现「同人」二字但没有指向既有作品、也没有材料,或处于否定语境(不要同人、别用原作设定),不触发,按普通原创卡处理。',
|
|
1156
1220
|
'- 用户说要同人但没给材料:问一句要不要上传;上传则继续;不传则取消该流程,按原创卡做,不再追问,也不留任何资料库文件。',
|
|
1157
1221
|
'- 对话附件先落盘到工作区的 .card-build/library/sources/ 再读取。',
|
|
1222
|
+
'- 用户想做同人但没材料时,给三条路:① 自己上传(推荐,免费、来源清楚);② 我帮你找(调用搜索与网页抓取,按次计费);③ 直接做原创卡。不要只问「传不传」。',
|
|
1223
|
+
'- 费用口径(必须准确):搜索与抓取都按成功请求次数计费,每 1000 次 5 元,即每次约 0.005 元;只有返回 200 且拿到内容才计费,失败、无结果、超时都不计费;count 不影响单价。你只能统计调用次数做估算,读不到用户账单,所以必须说「估算」,并补一句「实际以账单为准」。',
|
|
1224
|
+
'- 抓取前先报价(先报后做):说明预计搜索与抓取次数、估算金额,得到同意再执行;超过同意规模就停,先报已花费再问是否继续。',
|
|
1225
|
+
'- 只抓公开设定资料、百科条目、官方介绍,不抓同人全文;每条登记 url、抓取时间与 realm(默认 reference,来源不明记 unknown)。',
|
|
1226
|
+
'- 用户先说不上传、后来又改口要上传时,直接接着走上传分支,不要重复劝。',
|
|
1158
1227
|
'- 两个硬性停点:条目清单确认、两套取舍方案由用户选定(方案文档走 propose / approve-design)。未确认不写世界书。',
|
|
1159
1228
|
'- 产出分三份:世界书条目(进第一部分)、视觉参考(独立交付,给第二三部分)、资料库文件(留在 .card-build/library/)。',
|
|
1160
1229
|
'',
|