1
0
Fork 0

Refactor location scales

This commit is contained in:
Pabloader 2026-03-26 08:44:50 +00:00
parent 5359026466
commit f3d916982f
5 changed files with 32 additions and 38 deletions

View File

@ -7,6 +7,7 @@ export const highlight = (message: string, keepMarkup = true): string => {
const headerRegex = /#{1,3} $/;
const stack: string[] = [];
let inCodeBlock = false;
let inMonospaced = false;
let inHeader = false;
let lastIndex = 0;
let match: RegExpExecArray | null;
@ -30,6 +31,17 @@ export const highlight = (message: string, keepMarkup = true): string => {
continue;
}
if (inMonospaced) {
if (token === '`' && isClose) {
inMonospaced = false;
stack.pop();
resultHTML += `${keepToken ? token : ''}</span>`;
} else {
resultHTML += token;
}
continue;
}
const headerMatch = token.match(headerRegex);
if (headerMatch) {
if (inHeader) resultHTML += '</span>';
@ -68,6 +80,7 @@ export const highlight = (message: string, keepMarkup = true): string => {
resultHTML += `<span class="${styles.codeBlock}">${keepToken ? token : ''}`;
} else if (token === '`') {
stack.push(token);
inMonospaced = true;
resultHTML += `<span class="${styles.inlineCode}">${keepToken ? token : ''}`;
}
}

View File

@ -4,13 +4,6 @@ import styles from '../assets/location-editor.module.css';
import LLM from "../utils/llm";
import { ContentEditable } from "@common/components/ContentEditable";
const SCALE_OPTIONS = Object.entries(LocationScale)
.filter(([, value]) => typeof value === 'number')
.map(([label, value]) => ({
value,
label,
}));
export const LocationEditor = () => {
const { currentStory, dispatch, connection, model } = useAppState();
const [showDeleteConfirm, setShowDeleteConfirm] = useState<string | null>(null);
@ -127,11 +120,11 @@ export const LocationEditor = () => {
<select
class={styles.select}
value={location.scale}
onInput={(e) => handleEditLocation(location.id, 'scale', Number(e.currentTarget.value) as LocationScale)}
onInput={(e) => handleEditLocation(location.id, 'scale', e.currentTarget.value as LocationScale)}
>
{SCALE_OPTIONS.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
{Object.values(LocationScale).map((option) => (
<option key={option} value={option}>
{option.charAt(0).toUpperCase() + option.slice(1).toLowerCase()}
</option>
))}
</select>

View File

@ -38,15 +38,15 @@ export interface Character {
}
export enum LocationScale {
Room,
House,
Street,
City,
Region,
Country,
Continent,
World,
Universe,
Room = 'room',
House = 'house',
Street = 'street',
City = 'city',
Region = 'region',
Country = 'country',
Continent = 'continent',
World = 'world',
Universe = 'universe',
}
export interface Location {

View File

@ -1,6 +1,6 @@
import LLM from "./llm";
import Chapters from "./chapters";
import { type AppState, CharacterRole, LocationScale } from "../contexts/state";
import { type AppState, CharacterRole } from "../contexts/state";
import { Tools } from "./tools";
namespace Prompt {
@ -267,7 +267,7 @@ namespace Prompt {
lines.push(description);
}
lines.push(`**Scale:** ${LocationScale[location.scale]}`);
lines.push(`**Scale:** ${location.scale}`);
lines.push('');
}

View File

@ -1,21 +1,9 @@
import { formatErrorMessage } from "@common/errors";
import { Type, type Static, type TObject } from '@common/typebox';
import { CharacterRole, LocationScale, type AppState, type Character, type Location, type LoreEntry } from "../contexts/state";
import { CharacterRole, LocationScale, type AppState, type Character, type Location } from "../contexts/state";
import type LLM from "./llm";
const SCALE_DESCRIPTION = Object.entries(LocationScale)
.filter(([, value]) => typeof value === 'number')
.map(([key, value]) => `${value}=${key}`)
.join(', ');
const VALID_SCALES = Object.values(LocationScale).filter(v => typeof v === 'number');
const SCALE_NAMES = Object.fromEntries(
Object.entries(LocationScale)
.filter(([, value]) => typeof value === 'number')
.map(([key, value]) => [value, key])
);
const VALID_SCALES = Object.values(LocationScale);
const VALID_ROLES = Object.values(CharacterRole);
export namespace Tools {
@ -221,7 +209,7 @@ export namespace Tools {
if (location.description) {
result += `**Description:** ${location.description}\n\n`;
}
result += `**Scale:** ${SCALE_NAMES[location.scale]}\n`;
result += `**Scale:** ${location.scale}\n`;
return result.trim();
},
description: 'Get full information about a location by name',
@ -292,7 +280,7 @@ export namespace Tools {
shortDescription: Type.Optional(Type.String({ description: 'A brief description of the location (one line). Required when adding a new location.' })),
description: Type.Optional(Type.String({ description: 'Optional full location description' })),
scale: Type.Optional(Type.Enum(VALID_SCALES, {
description: `Location scale (enum): ${SCALE_DESCRIPTION}`,
description: `Location scale (enum): ${VALID_SCALES.join(', ')}`,
})),
}),
}),