diff --git a/src/common/highlight.ts b/src/common/highlight.ts index 3c3c15e..41ac074 100644 --- a/src/common/highlight.ts +++ b/src/common/highlight.ts @@ -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 : ''}`; + } else { + resultHTML += token; + } + continue; + } + const headerMatch = token.match(headerRegex); if (headerMatch) { if (inHeader) resultHTML += ''; @@ -68,6 +80,7 @@ export const highlight = (message: string, keepMarkup = true): string => { resultHTML += `${keepToken ? token : ''}`; } else if (token === '`') { stack.push(token); + inMonospaced = true; resultHTML += `${keepToken ? token : ''}`; } } diff --git a/src/games/storywriter/components/location-editor.tsx b/src/games/storywriter/components/location-editor.tsx index d11cf4f..af55af0 100644 --- a/src/games/storywriter/components/location-editor.tsx +++ b/src/games/storywriter/components/location-editor.tsx @@ -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(null); @@ -127,11 +120,11 @@ export const LocationEditor = () => { diff --git a/src/games/storywriter/contexts/state.tsx b/src/games/storywriter/contexts/state.tsx index 1365d1b..07b4485 100644 --- a/src/games/storywriter/contexts/state.tsx +++ b/src/games/storywriter/contexts/state.tsx @@ -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 { diff --git a/src/games/storywriter/utils/prompt.ts b/src/games/storywriter/utils/prompt.ts index f1d2ee6..6be23c1 100644 --- a/src/games/storywriter/utils/prompt.ts +++ b/src/games/storywriter/utils/prompt.ts @@ -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(''); } diff --git a/src/games/storywriter/utils/tools.ts b/src/games/storywriter/utils/tools.ts index d34d3bb..4362f1e 100644 --- a/src/games/storywriter/utils/tools.ts +++ b/src/games/storywriter/utils/tools.ts @@ -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(', ')}`, })), }), }),