中文 | English
gstinfo 是一个用于解析 SillyTavern 数据文件的 TypeScript 库,支持以下输入:
- 角色卡(PNG / JSON)
- 世界书(JSON,或从角色卡中自动提取绑定世界书)
- 预设(JSON)
- Gitee: https://gitee.com/al01/gstinfo
- GitHub: https://github.com/al01cn/gstinfo
gstinfo/
dist/
index.js
index.global.js
index.d.ts
src/
index.ts
package.json
tsconfig.json
如果你从包管理器使用:
npm install gstinfo
yarn add gstinfo
pnpm add gstinfo
bun add gstinfo如果你在当前仓库本地开发:
cd gstinfo
bun installcd gstinfo
bun run build
bunx tsc --noEmitgetCharacterInfo(input)getWorldInfo(input)getPresetsInfo(input)
三个函数在 Node 与浏览器下保持同一签名,均为 input 单参数。
- Node.js:支持
文件路径(string)、Buffer(Uint8Array)、Uint8Array、ArrayBuffer - 浏览器:支持
File/Blob、Uint8Array、ArrayBuffer
import { getCharacterInfo, getWorldInfo, getPresetsInfo } from "gstinfo";
const character = await getCharacterInfo("path/to/character.png");
const world = await getWorldInfo("path/to/world.json");
const preset = await getPresetsInfo("path/to/preset.json");import { readFile } from "node:fs/promises";
import { getCharacterInfo } from "gstinfo";
const buf = await readFile("path/to/character.png");
const character = await getCharacterInfo(buf);import { getCharacterInfo } from "gstinfo";
const input = document.querySelector<HTMLInputElement>("#fileInput");
const file = input?.files?.[0];
if (file) {
const character = await getCharacterInfo(file);
console.log(character);
}<script src="https://cdn.jsdelivr.net/npm/gstinfo@0.0.2/dist/index.global.js"></script>
<script>
const input = document.getElementById("fileInput");
input.addEventListener("change", async (event) => {
const file = event.target.files?.[0];
if (!file) return;
const character = await GSTInfo.getCharacterInfo(file);
console.log(character);
});
</script>import {
getCharacterInfo,
getWorldInfo,
getPresetsInfo,
getValueByPath,
isCharacterInfo,
isWorldInfo,
isPresetsInfo,
} from "./src/index.ts";
const character = await getCharacterInfo("path/to/character.png");
const world = await getWorldInfo("path/to/character.png");
const preset = await getPresetsInfo("path/to/preset.json");
const firstEntryContent = getValueByPath<string>(
character,
"worldInfo.entries[0].content",
""
);
const isValid =
isCharacterInfo(character) &&
isWorldInfo(world) &&
isPresetsInfo(preset);getCharacterInfo(file):返回结构化角色信息CharacterInfogetWorldInfo(file):返回结构化世界书信息WorldInfogetPresetsInfo(file):返回结构化预设信息PresetsInfogetValueByPath(obj, path, defaultValue):按路径安全读取任意字段isCharacterInfo / isWorldInfo / isPresetsInfo:模型类型守卫
CharacterInfo:角色基础字段、标签、世界书聚合、原始数据WorldInfo:世界书名称、条目列表、条目数量、原始数据WorldEntryInfo:世界书条目标准化字段(关键词、内容、开关等)PresetsInfo:预设来源、模型、采样参数、上下文参数、原始数据
- TypeScript
- Bun
- Node.js 内置模块(
fs/promises、zlib)
gstinfo is a TypeScript library for parsing SillyTavern-related data files:
- Character cards (PNG / JSON)
- World books (JSON, or auto-extracted from character cards)
- Presets (JSON)
- Gitee: https://gitee.com/al01/gstinfo
- GitHub: https://github.com/al01cn/gstinfo
gstinfo/
dist/
index.js
index.global.js
index.d.ts
src/
index.ts
package.json
tsconfig.json
From a package manager:
npm install gstinfo
yarn add gstinfo
pnpm add gstinfo
bun add gstinfoFor local development in this repository:
cd gstinfo
bun installcd gstinfo
bun run build
bunx tsc --noEmitgetCharacterInfo(input)getWorldInfo(input)getPresetsInfo(input)
The three functions share the same one-argument signature across Node and browsers.
- Node.js:
path(string),Buffer(Uint8Array),Uint8Array,ArrayBuffer - Browser:
File/Blob,Uint8Array,ArrayBuffer
import { getCharacterInfo, getWorldInfo, getPresetsInfo } from "gstinfo";
const character = await getCharacterInfo("path/to/character.png");
const world = await getWorldInfo("path/to/world.json");
const preset = await getPresetsInfo("path/to/preset.json");import { readFile } from "node:fs/promises";
import { getCharacterInfo } from "gstinfo";
const buf = await readFile("path/to/character.png");
const character = await getCharacterInfo(buf);import { getCharacterInfo } from "gstinfo";
const input = document.querySelector<HTMLInputElement>("#fileInput");
const file = input?.files?.[0];
if (file) {
const character = await getCharacterInfo(file);
console.log(character);
}<script src="https://cdn.jsdelivr.net/npm/gstinfo@0.0.2/dist/index.global.js"></script>
<script>
const input = document.getElementById("fileInput");
input.addEventListener("change", async (event) => {
const file = event.target.files?.[0];
if (!file) return;
const character = await GSTInfo.getCharacterInfo(file);
console.log(character);
});
</script>import {
getCharacterInfo,
getWorldInfo,
getPresetsInfo,
getValueByPath,
isCharacterInfo,
isWorldInfo,
isPresetsInfo,
} from "./src/index.ts";
const character = await getCharacterInfo("path/to/character.png");
const world = await getWorldInfo("path/to/character.png");
const preset = await getPresetsInfo("path/to/preset.json");
const firstEntryContent = getValueByPath<string>(
character,
"worldInfo.entries[0].content",
""
);
const isValid =
isCharacterInfo(character) &&
isWorldInfo(world) &&
isPresetsInfo(preset);getCharacterInfo(file): returns structured character info (CharacterInfo)getWorldInfo(file): returns structured world-book info (WorldInfo)getPresetsInfo(file): returns structured preset info (PresetsInfo)getValueByPath(obj, path, defaultValue): safely access nested valuesisCharacterInfo / isWorldInfo / isPresetsInfo: type guards
CharacterInfo: core character fields, tags, world-book aggregate, raw dataWorldInfo: world-book name, entries, entry count, raw dataWorldEntryInfo: normalized world entry fields (keys, content, enabled, etc.)PresetsInfo: source, model, sampling/context params, raw data
- TypeScript
- Bun
- Node.js built-in modules (
fs/promises,zlib)