Refactor location scales
This commit is contained in:
parent
5359026466
commit
f3d916982f
|
|
@ -7,6 +7,7 @@ export const highlight = (message: string, keepMarkup = true): string => {
|
||||||
const headerRegex = /#{1,3} $/;
|
const headerRegex = /#{1,3} $/;
|
||||||
const stack: string[] = [];
|
const stack: string[] = [];
|
||||||
let inCodeBlock = false;
|
let inCodeBlock = false;
|
||||||
|
let inMonospaced = false;
|
||||||
let inHeader = false;
|
let inHeader = false;
|
||||||
let lastIndex = 0;
|
let lastIndex = 0;
|
||||||
let match: RegExpExecArray | null;
|
let match: RegExpExecArray | null;
|
||||||
|
|
@ -30,6 +31,17 @@ export const highlight = (message: string, keepMarkup = true): string => {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (inMonospaced) {
|
||||||
|
if (token === '`' && isClose) {
|
||||||
|
inMonospaced = false;
|
||||||
|
stack.pop();
|
||||||
|
resultHTML += `${keepToken ? token : ''}</span>`;
|
||||||
|
} else {
|
||||||
|
resultHTML += token;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const headerMatch = token.match(headerRegex);
|
const headerMatch = token.match(headerRegex);
|
||||||
if (headerMatch) {
|
if (headerMatch) {
|
||||||
if (inHeader) resultHTML += '</span>';
|
if (inHeader) resultHTML += '</span>';
|
||||||
|
|
@ -68,6 +80,7 @@ export const highlight = (message: string, keepMarkup = true): string => {
|
||||||
resultHTML += `<span class="${styles.codeBlock}">${keepToken ? token : ''}`;
|
resultHTML += `<span class="${styles.codeBlock}">${keepToken ? token : ''}`;
|
||||||
} else if (token === '`') {
|
} else if (token === '`') {
|
||||||
stack.push(token);
|
stack.push(token);
|
||||||
|
inMonospaced = true;
|
||||||
resultHTML += `<span class="${styles.inlineCode}">${keepToken ? token : ''}`;
|
resultHTML += `<span class="${styles.inlineCode}">${keepToken ? token : ''}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,6 @@ import styles from '../assets/location-editor.module.css';
|
||||||
import LLM from "../utils/llm";
|
import LLM from "../utils/llm";
|
||||||
import { ContentEditable } from "@common/components/ContentEditable";
|
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 = () => {
|
export const LocationEditor = () => {
|
||||||
const { currentStory, dispatch, connection, model } = useAppState();
|
const { currentStory, dispatch, connection, model } = useAppState();
|
||||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState<string | null>(null);
|
const [showDeleteConfirm, setShowDeleteConfirm] = useState<string | null>(null);
|
||||||
|
|
@ -127,11 +120,11 @@ export const LocationEditor = () => {
|
||||||
<select
|
<select
|
||||||
class={styles.select}
|
class={styles.select}
|
||||||
value={location.scale}
|
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) => (
|
{Object.values(LocationScale).map((option) => (
|
||||||
<option key={option.value} value={option.value}>
|
<option key={option} value={option}>
|
||||||
{option.label}
|
{option.charAt(0).toUpperCase() + option.slice(1).toLowerCase()}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
|
|
|
||||||
|
|
@ -38,15 +38,15 @@ export interface Character {
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum LocationScale {
|
export enum LocationScale {
|
||||||
Room,
|
Room = 'room',
|
||||||
House,
|
House = 'house',
|
||||||
Street,
|
Street = 'street',
|
||||||
City,
|
City = 'city',
|
||||||
Region,
|
Region = 'region',
|
||||||
Country,
|
Country = 'country',
|
||||||
Continent,
|
Continent = 'continent',
|
||||||
World,
|
World = 'world',
|
||||||
Universe,
|
Universe = 'universe',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Location {
|
export interface Location {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import LLM from "./llm";
|
import LLM from "./llm";
|
||||||
import Chapters from "./chapters";
|
import Chapters from "./chapters";
|
||||||
import { type AppState, CharacterRole, LocationScale } from "../contexts/state";
|
import { type AppState, CharacterRole } from "../contexts/state";
|
||||||
import { Tools } from "./tools";
|
import { Tools } from "./tools";
|
||||||
|
|
||||||
namespace Prompt {
|
namespace Prompt {
|
||||||
|
|
@ -267,7 +267,7 @@ namespace Prompt {
|
||||||
lines.push(description);
|
lines.push(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
lines.push(`**Scale:** ${LocationScale[location.scale]}`);
|
lines.push(`**Scale:** ${location.scale}`);
|
||||||
lines.push('');
|
lines.push('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,9 @@
|
||||||
import { formatErrorMessage } from "@common/errors";
|
import { formatErrorMessage } from "@common/errors";
|
||||||
import { Type, type Static, type TObject } from '@common/typebox';
|
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";
|
import type LLM from "./llm";
|
||||||
|
|
||||||
const SCALE_DESCRIPTION = Object.entries(LocationScale)
|
const VALID_SCALES = Object.values(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_ROLES = Object.values(CharacterRole);
|
const VALID_ROLES = Object.values(CharacterRole);
|
||||||
|
|
||||||
export namespace Tools {
|
export namespace Tools {
|
||||||
|
|
@ -221,7 +209,7 @@ export namespace Tools {
|
||||||
if (location.description) {
|
if (location.description) {
|
||||||
result += `**Description:** ${location.description}\n\n`;
|
result += `**Description:** ${location.description}\n\n`;
|
||||||
}
|
}
|
||||||
result += `**Scale:** ${SCALE_NAMES[location.scale]}\n`;
|
result += `**Scale:** ${location.scale}\n`;
|
||||||
return result.trim();
|
return result.trim();
|
||||||
},
|
},
|
||||||
description: 'Get full information about a location by name',
|
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.' })),
|
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' })),
|
description: Type.Optional(Type.String({ description: 'Optional full location description' })),
|
||||||
scale: Type.Optional(Type.Enum(VALID_SCALES, {
|
scale: Type.Optional(Type.Enum(VALID_SCALES, {
|
||||||
description: `Location scale (enum): ${SCALE_DESCRIPTION}`,
|
description: `Location scale (enum): ${VALID_SCALES.join(', ')}`,
|
||||||
})),
|
})),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue