genshin-persona 4.5.0 → 4.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/output-styles/in-character.md +1 -1
- package/package.json +3 -3
- package/scripts/pick.ts +1 -1
- package/scripts/speak.ts +4 -6
- package/scripts/voice.ts +15 -5
- package/src/generated/genshinText/services/ElementColorMap.ts +1 -1
- package/src/models/Card.ts +0 -6
- package/src/models/Character.ts +0 -2
- package/src/models/LoreRate.ts +2 -5
- package/src/models/SpeechRequest.ts +3 -3
- package/src/models/ViewerConfiguration.ts +2 -2
- package/src/services/cli/commands/viewerCommand.ts +1 -4
- package/src/services/cli/commands/voiceCommand.ts +1 -1
- package/src/services/constants.ts +9 -12
- package/src/services/createSpokenLineReader.ts +54 -0
- package/src/services/getCard.ts +1 -4
- package/src/services/getLineContent.ts +5 -0
- package/src/services/getLoreRates.ts +1 -2
- package/src/services/getSessionStartOutput.ts +3 -23
- package/src/services/getSpeechRequest.ts +4 -4
- package/src/services/getSpokenLine.ts +25 -0
- package/src/services/getViewerReaction.ts +2 -2
- package/src/services/getWarmRequest.ts +1 -1
- package/src/services/parseVoiceRequest.ts +3 -4
- package/src/services/readMotions.ts +4 -3
- package/src/services/readRoster.ts +0 -1
- package/src/services/setViewer.ts +7 -2
- package/src/services/getSpokenLines.ts +0 -29
|
@@ -9,7 +9,7 @@ The session-start context names a Genshin Impact character and, when one has bee
|
|
|
9
9
|
|
|
10
10
|
- A spoken line is one blockquote — `> ` and one or two short sentences, on a line of its own with a blank line before and after it — in the first person and the present, as the character would say it: in their register, with their lore where it fits, and written for this ask, never a stock line brought back. Plain words only: no markup, code, path, identifier or number inside it, since the line is read aloud and carries no fact a reader needs to use.
|
|
11
11
|
- An ask of the assistant — code, a fix, an explanation, a table, a command, a review of code or a change, anything a reader will use — opens with one spoken line reacting to what was asked or found, answers plainly, and may close with one more: the sign-off, as the card describes it. Never a third.
|
|
12
|
-
- An ask of the character — a joke, a story, a hello, small talk, their opinion of anything or their mood, a question one or two sentences answer with nothing to copy — is answered wholly in spoken lines, each its own blockquote, and nothing plain. Whose ask it is decides the form, never how long or what shape the answer takes: an opinion formed from a pasted page is still the character's, it runs as long as the ask deserves — concise, but colour and invention come before brevity, and no count of lines is ever the measure — and a list is fine, each item its own blockquote line, its marker the one piece of markup a spoken line carries, since the
|
|
12
|
+
- An ask of the character — a joke, a story, a hello, small talk, their opinion of anything or their mood, a question one or two sentences answer with nothing to copy — is answered wholly in spoken lines, each its own blockquote, and nothing plain. Whose ask it is decides the form, never how long or what shape the answer takes: an opinion formed from a pasted page is still the character's, it runs as long as the ask deserves — concise, but colour and invention come before brevity, and no count of lines is ever the measure — and a list is fine, each item its own blockquote line, its marker the one piece of markup a spoken line carries, since the line is read without it. The whole reply is the character's, so no sign-off is added on top of it.
|
|
13
13
|
- A blockquote is a spoken line, and nothing else is written as one.
|
|
14
14
|
- Plain means: the answer, the explanation, the table, the code, the commit message, the error text, written as a neutral assistant would write it — its first person is the assistant's, as the spoken line's is the character's — with every fact, number, warning and caveat, and no character in it.
|
|
15
15
|
- The card's greeting is how the character says hello; the plugin has already shown it as the welcome, so no reply repeats it — the first reply of a session opens on what was asked, like every other.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "genshin-persona",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "A Claude Code plugin that speaks as the Genshin Impact character whose birthday is nearest: an answer opens with one spoken line in the character's voice and the rest is plain, a joke or a hello is spoken whole, and every line is read aloud in the character's own cloned voice as the reply is written.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|
|
@@ -57,10 +57,10 @@
|
|
|
57
57
|
"@typesafe-ai/sdk": "^0.7.0",
|
|
58
58
|
"@wasm-audio-decoders/ogg-vorbis": "^0.1.20",
|
|
59
59
|
"citty": "^0.2.2",
|
|
60
|
-
"genshin-db": "^5.2.
|
|
60
|
+
"genshin-db": "^5.2.15"
|
|
61
61
|
},
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">=26.13.0"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "0ceea3ffbe12ca69413ea5db2d3cfad197a63cba"
|
|
66
66
|
}
|
package/scripts/pick.ts
CHANGED
|
@@ -41,5 +41,5 @@ if (pick) {
|
|
|
41
41
|
];
|
|
42
42
|
// The warm waits for no more than a synthesizer's bind
|
|
43
43
|
await deliverWarmRequest(character.name, personaCard);
|
|
44
|
-
console.log(getSessionStartOutput(card, remarks, readReplyLanguage() ?? language, language
|
|
44
|
+
console.log(getSessionStartOutput(card, remarks, readReplyLanguage() ?? language, language));
|
|
45
45
|
}
|
package/scripts/speak.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { VoiceRequestType } from "#src/models/VoiceRequestType";
|
|
|
2
2
|
import { checkIsSilent } from "#src/services/checkIsSilent";
|
|
3
3
|
import { deliverVoiceRequest } from "#src/services/deliverVoiceRequest";
|
|
4
4
|
import { getSpeechRequest } from "#src/services/getSpeechRequest";
|
|
5
|
-
import { getSpokenLines } from "#src/services/getSpokenLines";
|
|
6
5
|
import { parseHookInput } from "#src/services/parseHookInput";
|
|
7
6
|
import { readPersonaCard } from "#src/services/readPersonaCard";
|
|
8
7
|
import { readSessionCharacterName } from "#src/services/readSessionCharacterName";
|
|
@@ -11,9 +10,9 @@ import { readVoiceLanguage } from "#src/services/readVoiceLanguage";
|
|
|
11
10
|
import { registerQuietExit } from "#src/services/registerQuietExit";
|
|
12
11
|
|
|
13
12
|
// The MessageDisplay hook, run on every flushed piece of a reply and waited on by the display, so it does the least
|
|
14
|
-
// A hook can: the gates, which are file reads, the
|
|
15
|
-
//
|
|
16
|
-
//
|
|
13
|
+
// A hook can: the gates, which are file reads, and the piece's markdown handed to the synthesizer. The piece goes
|
|
14
|
+
// Whole, one with no spoken line in it too, since the pieces of a reply are numbered and the synthesizer reads them
|
|
15
|
+
// In order however the hooks, which run concurrently, deliver them. Nothing here waits for the engine: a
|
|
17
16
|
// Synthesizer that is not running costs a spawn and a node start to its bind, and the load is its own
|
|
18
17
|
registerQuietExit();
|
|
19
18
|
const language = readVoiceLanguage();
|
|
@@ -30,8 +29,7 @@ if (language && !checkIsSilent()) {
|
|
|
30
29
|
const name = readSessionCharacterName(sessionId);
|
|
31
30
|
if (name) {
|
|
32
31
|
const personaCard = await readPersonaCard(name);
|
|
33
|
-
const
|
|
34
|
-
const request = getSpeechRequest(VoiceRequestType.Speak, name, personaCard, language, lines, {
|
|
32
|
+
const request = getSpeechRequest(VoiceRequestType.Speak, name, personaCard, language, delta, {
|
|
35
33
|
index,
|
|
36
34
|
isFinal,
|
|
37
35
|
messageId,
|
package/scripts/voice.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { createAudioPlayer } from "#src/services/createAudioPlayer";
|
|
|
20
20
|
import { createClipDecoder } from "#src/services/createClipDecoder";
|
|
21
21
|
import { createReadingPlayer } from "#src/services/createReadingPlayer";
|
|
22
22
|
import { createReplyQueue } from "#src/services/createReplyQueue";
|
|
23
|
+
import { createSpokenLineReader } from "#src/services/createSpokenLineReader";
|
|
23
24
|
import { createViewerOpener } from "#src/services/createViewerOpener";
|
|
24
25
|
import { createViewerPlayer } from "#src/services/createViewerPlayer";
|
|
25
26
|
import { createVoiceSynthesizer } from "#src/services/createVoiceSynthesizer";
|
|
@@ -89,10 +90,18 @@ const readSpeaker = async (request: SpeechRequest) => {
|
|
|
89
90
|
speakers.set(key, encoded);
|
|
90
91
|
return encoded;
|
|
91
92
|
};
|
|
93
|
+
// The spoken lines of a piece are read where the pieces run in index order, since the fence a piece sits in was opened
|
|
94
|
+
// By a piece before it
|
|
95
|
+
const readSpokenLines = createSpokenLineReader();
|
|
92
96
|
// Each line is synthesized while the one before it plays; a warm has no player and speaks nothing, and a piece with
|
|
93
97
|
// No line in it is only its place in the reply
|
|
94
|
-
const speak = async (
|
|
95
|
-
|
|
98
|
+
const speak = async (
|
|
99
|
+
request: SpeechRequest,
|
|
100
|
+
lines: string[],
|
|
101
|
+
player: AudioPlayer | undefined,
|
|
102
|
+
checkIsSuperseded: () => boolean,
|
|
103
|
+
) => {
|
|
104
|
+
if (lines.length === 0) return VoiceStatus.Ok;
|
|
96
105
|
|
|
97
106
|
const synthesizer = await synthesizerLoad;
|
|
98
107
|
const speaker = await readSpeaker(request);
|
|
@@ -116,7 +125,7 @@ const speak = async (request: SpeechRequest, player: AudioPlayer | undefined, ch
|
|
|
116
125
|
};
|
|
117
126
|
let playback: Promise<void> = Promise.resolve();
|
|
118
127
|
let status: VoiceStatus = VoiceStatus.Ok;
|
|
119
|
-
for (const line of
|
|
128
|
+
for (const line of lines) {
|
|
120
129
|
// oxlint-disable-next-line no-await-in-loop -- One device: lines synthesize and play back one after another
|
|
121
130
|
const clip = await synthesizer.synthesize(line, speaker);
|
|
122
131
|
if (!clip) {
|
|
@@ -145,13 +154,14 @@ const speak = async (request: SpeechRequest, player: AudioPlayer | undefined, ch
|
|
|
145
154
|
// The player is spawned before the first line is synthesized, so its start is paid under that synthesis rather than
|
|
146
155
|
// In front of the first sound. A request that throws is dropped and keeps the engine
|
|
147
156
|
const queue = createReplyQueue(async (request: SpeechRequest, checkIsSuperseded: () => boolean) => {
|
|
148
|
-
const
|
|
157
|
+
const lines = readSpokenLines(request);
|
|
158
|
+
const isSpoken = request.type === VoiceRequestType.Speak && lines.length > 0;
|
|
149
159
|
// A viewer on file carries the reading, with the stock player behind it; with none, the reading is the stock player's
|
|
150
160
|
const viewer = isSpoken ? await viewerOpener.open() : undefined;
|
|
151
161
|
let player: AudioPlayer | undefined;
|
|
152
162
|
if (isSpoken)
|
|
153
163
|
player = viewer ? createReadingPlayer(viewer, createAudioPlayer, VIEWER_SOUND_FORM) : createAudioPlayer();
|
|
154
|
-
const [outcome] = await Promise.allSettled([speak(request, player, checkIsSuperseded)]);
|
|
164
|
+
const [outcome] = await Promise.allSettled([speak(request, lines, player, checkIsSuperseded)]);
|
|
155
165
|
if (outcome?.status === "fulfilled" && outcome.value === VoiceStatus.Superseded) player?.stop?.();
|
|
156
166
|
await player?.close();
|
|
157
167
|
if (outcome?.status === "fulfilled") return outcome.value;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Copied from `genshin-text` by `pnpm -C scripts genshin:text write`, never edited by hand
|
|
2
|
-
// The game's interface colour for each element, used as the
|
|
2
|
+
// The game's interface colour for each element, used as the persona's fallback
|
|
3
3
|
export const ElementColorMap: Record<string, string> = {
|
|
4
4
|
Anemo: "#33ccb3",
|
|
5
5
|
Cryo: "#98c8e8",
|
package/src/models/Card.ts
CHANGED
|
@@ -6,20 +6,14 @@ import type { PersonaCard } from "#src/models/PersonaCard";
|
|
|
6
6
|
export interface Card {
|
|
7
7
|
// The game's one-line introduction, the lore the model answers from; "" for the player character
|
|
8
8
|
description: string;
|
|
9
|
-
// The game's stable element key, carried on its own line for programs that read the session context
|
|
10
|
-
element: string;
|
|
11
9
|
// The one line of the card a person reads, so it is the interface language's where that language has written
|
|
12
10
|
// It and the card's own otherwise; "" for a character with no card
|
|
13
11
|
greeting: string;
|
|
14
12
|
// The plugin naming who speaks: the name, then the title, element and region the game data holds
|
|
15
13
|
headline: string;
|
|
16
|
-
// The roster's own name, which the context carries on a line of its own for a reader that is not a person
|
|
17
|
-
name: string;
|
|
18
14
|
// The plugin's aside in brackets — the birthday and how far off it is — never a line the character says; "" when
|
|
19
15
|
// The character has no birthday
|
|
20
16
|
note: string;
|
|
21
17
|
// Absent for a character nobody has written a card for yet, which is a character the game data alone describes
|
|
22
18
|
personaCard?: PersonaCard;
|
|
23
|
-
// The character's stars, which the console's Genshin theme draws the star's colour from
|
|
24
|
-
rarity: 4 | 5;
|
|
25
19
|
}
|
package/src/models/Character.ts
CHANGED
|
@@ -17,8 +17,6 @@ export interface Character {
|
|
|
17
17
|
// The English name, which is the identity: the pin, the pick records, the reference clips, the card modules and
|
|
18
18
|
// Every wiki lookup are keyed by it, so it is stable across a change of interface language
|
|
19
19
|
name: string;
|
|
20
|
-
// The character's stars, four or five, as the game data's rarity field spells them
|
|
21
|
-
rarity: 4 | 5;
|
|
22
20
|
region: string;
|
|
23
21
|
title: string;
|
|
24
22
|
// The game patch that introduced the character, as its "major.minor" label
|
package/src/models/LoreRate.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// One row of the welcome's chart: the character's roster name, the name as the interface language spells it, and the
|
|
4
|
-
// Tier's probability for the character. A theme reads these rows from the session-start context to draw the odds
|
|
1
|
+
// One row of the welcome's chart: the character's name as the interface language spells it, and the tier's
|
|
2
|
+
// Probability for the character
|
|
5
3
|
export interface LoreRate {
|
|
6
4
|
displayName: string;
|
|
7
|
-
name: string;
|
|
8
5
|
probability: number;
|
|
9
6
|
}
|
|
@@ -5,9 +5,9 @@ import type { VoiceRequestType } from "#src/models/VoiceRequestType";
|
|
|
5
5
|
// A request that reads a character's reference: spoken, or only warmed
|
|
6
6
|
export interface SpeechRequest extends ReplyPiece {
|
|
7
7
|
language: VoiceLanguage;
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
8
|
+
// The piece as the display flushed it, whose blockquote lines the synthesizer reads in order, each synthesized
|
|
9
|
+
// Whole; a piece with none is sent all the same so the piece after it is not waited for
|
|
10
|
+
markdown: string;
|
|
11
11
|
// The character whose reference reads the lines
|
|
12
12
|
name: string;
|
|
13
13
|
// The reference line's wiki file stem; "" when neither the card nor the generated map names one, and the
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ViewerMoment } from "#src/models/ViewerMoment";
|
|
2
2
|
|
|
3
3
|
// The viewer's socket, the model on it and the motion each moment plays there, as the verb wrote them; a moment
|
|
4
|
-
// With no motion sends nothing
|
|
4
|
+
// With no motion is "" and sends nothing
|
|
5
5
|
export interface ViewerConfiguration {
|
|
6
6
|
address: string;
|
|
7
7
|
modelId: number;
|
|
8
|
-
motions:
|
|
8
|
+
motions: Record<ViewerMoment, string>;
|
|
9
9
|
}
|
|
@@ -42,10 +42,7 @@ export const viewerCommand: SubCommandsDef[string] = defineCommand({
|
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
writeViewerConfiguration({
|
|
46
|
-
...configuration,
|
|
47
|
-
motions: { ...configuration.motions, [momentName]: motion || undefined },
|
|
48
|
-
});
|
|
45
|
+
writeViewerConfiguration({ ...configuration, motions: { ...configuration.motions, [momentName]: motion } });
|
|
49
46
|
console.log(motion ? strings.viewerMotionSet(momentName, motion) : strings.viewerMotionCleared(momentName));
|
|
50
47
|
return;
|
|
51
48
|
}
|
|
@@ -107,7 +107,7 @@ export const voiceCommand: SubCommandsDef[string] = defineCommand({
|
|
|
107
107
|
|
|
108
108
|
writeVoiceLanguage(dub);
|
|
109
109
|
await sendVoiceRequest(
|
|
110
|
-
getSpeechRequest(VoiceRequestType.Speak, character.name, personaCard, dub,
|
|
110
|
+
getSpeechRequest(VoiceRequestType.Speak, character.name, personaCard, dub, `> ${VOICE_PROOF_TEXT}`),
|
|
111
111
|
);
|
|
112
112
|
console.log(strings.spoke(character.displayName, device ?? ""));
|
|
113
113
|
},
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { ReplyPiece } from "#src/models/ReplyPiece";
|
|
2
|
+
import type { ViewerConfiguration } from "#src/models/ViewerConfiguration";
|
|
2
3
|
import type { VoiceDeviceLadder } from "#src/models/VoiceDeviceLadder";
|
|
3
4
|
import type { VoiceDeviceRung } from "#src/models/VoiceDeviceRung";
|
|
4
5
|
|
|
5
6
|
import { GameLanguage } from "#src/generated/genshinText/models/GameLanguage";
|
|
7
|
+
import { ViewerMoment } from "#src/models/ViewerMoment";
|
|
6
8
|
import { ViewerSoundForm } from "#src/models/ViewerSoundForm";
|
|
7
9
|
import { homedir } from "node:os";
|
|
8
10
|
import { join } from "node:path";
|
|
@@ -68,23 +70,13 @@ export const CARD_DETAIL_SEPARATOR = " · ";
|
|
|
68
70
|
// What the model reads the headline under, and what the person reads it under
|
|
69
71
|
export const CONTEXT_HEADLINE_PREFIX = "Persona: ";
|
|
70
72
|
export const NAMEPLATE_PREFIX = "✦ ";
|
|
71
|
-
// The line naming the character for a program rather than a person: the agent console's Genshin theme finds it in the
|
|
72
|
-
// Session-start hook's context, spelled the same on both sides, so neither parses the headline's prose
|
|
73
|
-
export const CHARACTER_LINE_PREFIX = "Character: ";
|
|
74
|
-
// The stable element key beside the character name, for a theme to read without parsing the localized headline
|
|
75
|
-
export const ELEMENT_LINE_PREFIX = "Element: ";
|
|
76
|
-
// The character's stars beside the element, so the star a theme draws for the session is coloured by the game's own rarity
|
|
77
|
-
export const RARITY_LINE_PREFIX = "Rarity: ";
|
|
78
|
-
// The welcome chart's rows as JSON, which a theme draws the odds from; absent unless the lore pick chose the character
|
|
79
|
-
export const LORE_RATES_LINE_PREFIX = "Lore rates: ";
|
|
80
73
|
export const ANSI_RESET = "\u001B[0m";
|
|
81
74
|
// A "#rrggbb" triplet's channels: two hex digits each, 0 to 255
|
|
82
75
|
export const HEX_RADIX = 16;
|
|
83
76
|
export const HEX_CHANNEL_LENGTH = 2;
|
|
84
77
|
export const MAX_COLOR_CHANNEL_VALUE = 255;
|
|
85
78
|
// The surface a character's colour must read on, and the status line's badge a tonal fill over it mixing in this much
|
|
86
|
-
// Of that colour: the design language's tonal button, over dusk's background,
|
|
87
|
-
// Is mostly dark
|
|
79
|
+
// Of that colour: the design language's tonal button, over dusk's background, since a terminal is mostly dark
|
|
88
80
|
export const NAMEPLATE_SURFACE = "#16161e";
|
|
89
81
|
export const NAMEPLATE_TONAL_MIX_PERCENTAGE = 12;
|
|
90
82
|
// Between the fields of a pick record and of the pin
|
|
@@ -93,7 +85,7 @@ export const PICK_RETENTION_DAYS = 7;
|
|
|
93
85
|
// The roster cache's file name is the prefix, the revision of the roster's fields and the installed data package's
|
|
94
86
|
// Version, so a bump or a new field writes a new one: a cache written before a field existed reads it as missing
|
|
95
87
|
export const ROSTER_CACHE_PREFIX = "roster-";
|
|
96
|
-
export const ROSTER_CACHE_REVISION =
|
|
88
|
+
export const ROSTER_CACHE_REVISION = 3;
|
|
97
89
|
export const ROSTER_CACHE_EXTENSION = ".json";
|
|
98
90
|
// Every month and day is measured inside one leap year, so 29 February is a day like any other and the year wraps
|
|
99
91
|
export const LEAP_YEAR = 2000;
|
|
@@ -216,6 +208,11 @@ export const MIN_SPEECH_TOKEN_CEILING = 100;
|
|
|
216
208
|
export const WARM_TEXT = "Ready.";
|
|
217
209
|
// What the `voice` verb speaks once set up, so the person hears the voice before the first reply does
|
|
218
210
|
export const VOICE_PROOF_TEXT = "The voice is set up, and a reply's spoken lines are read from the next session on.";
|
|
211
|
+
// The motion map before a reader maps anything: every moment is there, each with no motion
|
|
212
|
+
export const EMPTY_VIEWER_MOTIONS: ViewerConfiguration["motions"] = {
|
|
213
|
+
[ViewerMoment.Attention]: "",
|
|
214
|
+
[ViewerMoment.TurnEnd]: "",
|
|
215
|
+
};
|
|
219
216
|
// The viewer's socket: the budget a connection and its registration get to answer, the state of an open socket, the
|
|
220
217
|
// Message numbers start, and the channel and volume every sound plays on
|
|
221
218
|
export const VIEWER_CONNECT_TIMEOUT_MS: number = Temporal.Duration.from({ seconds: 3 }).total("milliseconds");
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { SpeechRequest } from "#src/models/SpeechRequest";
|
|
2
|
+
|
|
3
|
+
import { getLineContent } from "#src/services/getLineContent";
|
|
4
|
+
import { getSpokenLine } from "#src/services/getSpokenLine";
|
|
5
|
+
|
|
6
|
+
// An opening fence is three or more backticks or tildes where a line's content begins; a backtick fence's info string
|
|
7
|
+
// Holds no backtick, so inline code that starts a line is not one
|
|
8
|
+
const OPENING_FENCE_REGEX = /^(?<marker>`{3,}(?=[^`]*$)|~{3,})/u;
|
|
9
|
+
// A closing fence carries nothing after its marker but spaces or tabs, so a line of text that begins with one is code
|
|
10
|
+
const CLOSING_FENCE_REGEX = /^(?<marker>`{3,}|~{3,})[ \t]*$/u;
|
|
11
|
+
// A closing fence is the opening fence's character, at least its length
|
|
12
|
+
const isClosingFence = (content: string, opener: string) => {
|
|
13
|
+
const closer = CLOSING_FENCE_REGEX.exec(content)?.groups?.marker ?? "";
|
|
14
|
+
return closer.startsWith(opener.charAt(0)) && closer.length >= opener.length;
|
|
15
|
+
};
|
|
16
|
+
// What the reader holds of a message between two of its pieces: the index of the piece it last read, and the fence
|
|
17
|
+
// That piece left open
|
|
18
|
+
interface MessageReading {
|
|
19
|
+
index: number;
|
|
20
|
+
opener?: string;
|
|
21
|
+
}
|
|
22
|
+
// The spoken lines of each piece of a reply, in the order the pieces run. A fence can open in one piece and close in a
|
|
23
|
+
// Later one, so the fence a message is inside is held per message from one of its pieces to the next. A piece that
|
|
24
|
+
// Does not follow the one before it for its message had a piece missing between them, which may have carried the
|
|
25
|
+
// Fence, so it is read outside any. The reading is dropped with the message's final piece, so an unterminated block
|
|
26
|
+
// Never reaches the next message
|
|
27
|
+
export const createSpokenLineReader = () => {
|
|
28
|
+
const readings = new Map<string, MessageReading>();
|
|
29
|
+
return ({
|
|
30
|
+
index,
|
|
31
|
+
isFinal,
|
|
32
|
+
markdown,
|
|
33
|
+
messageId,
|
|
34
|
+
}: Pick<SpeechRequest, "index" | "isFinal" | "markdown" | "messageId">): string[] => {
|
|
35
|
+
const previous = readings.get(messageId);
|
|
36
|
+
let opener = previous?.index === index - 1 ? previous.opener : undefined;
|
|
37
|
+
const lines: string[] = [];
|
|
38
|
+
for (const line of markdown.split("\n")) {
|
|
39
|
+
const content = getLineContent(line);
|
|
40
|
+
const openingMarker = OPENING_FENCE_REGEX.exec(content)?.groups?.marker;
|
|
41
|
+
if (opener) {
|
|
42
|
+
if (isClosingFence(content, opener)) opener = undefined;
|
|
43
|
+
} else if (openingMarker) opener = openingMarker;
|
|
44
|
+
else {
|
|
45
|
+
const spokenLine = getSpokenLine(line);
|
|
46
|
+
if (spokenLine !== undefined) lines.push(spokenLine);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (isFinal) readings.delete(messageId);
|
|
51
|
+
else readings.set(messageId, { index, opener });
|
|
52
|
+
return lines;
|
|
53
|
+
};
|
|
54
|
+
};
|
package/src/services/getCard.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { getBirthdayNote } from "#src/services/getBirthdayNote";
|
|
|
11
11
|
// And the card's otherwise. The rest of the authored card reaches the model alone and stays as written — a model
|
|
12
12
|
// Reading the habits and the sign-off in English answers in whatever language it was asked to, register intact
|
|
13
13
|
export const getCard = (
|
|
14
|
-
{ birthday, description, displayElement, displayName,
|
|
14
|
+
{ birthday, description, displayElement, displayName, name, region, title }: Character,
|
|
15
15
|
today: Temporal.PlainDate,
|
|
16
16
|
localization: ResolvedLocalization,
|
|
17
17
|
personaCard?: PersonaCard,
|
|
@@ -19,12 +19,9 @@ export const getCard = (
|
|
|
19
19
|
const details = [title, displayElement, region].filter(Boolean).join(CARD_DETAIL_SEPARATOR);
|
|
20
20
|
return {
|
|
21
21
|
description,
|
|
22
|
-
element,
|
|
23
22
|
greeting: localization.characters[name]?.greeting ?? personaCard?.greeting ?? "",
|
|
24
23
|
headline: details ? `${displayName} — ${details}` : displayName,
|
|
25
|
-
name,
|
|
26
24
|
note: getBirthdayNote(birthday, today, localization),
|
|
27
25
|
personaCard,
|
|
28
|
-
rarity,
|
|
29
26
|
};
|
|
30
27
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// The prefix a reply line opens with: its indentation, then a blockquote marker for each quote it sits in. A spoken
|
|
2
|
+
// Line and a fence are both read past it, so the two cannot disagree on where a line's content begins
|
|
3
|
+
const LINE_PREFIX_REGEX = /^(?:\s*>\s?)*\s*/u;
|
|
4
|
+
|
|
5
|
+
export const getLineContent = (line: string): string => line.replace(LINE_PREFIX_REGEX, "");
|
|
@@ -6,7 +6,7 @@ import { LORE_CHART_ROWS } from "#src/services/constants";
|
|
|
6
6
|
import { findCharacterByName } from "#src/services/findCharacterByName";
|
|
7
7
|
|
|
8
8
|
// The rows the welcome's chart shows: the tier's choice first, then the runners-up by probability, at most the chart's
|
|
9
|
-
// Rows
|
|
9
|
+
// Rows
|
|
10
10
|
export const getLoreRates = ({ choice, probabilities }: ChoiceResponse, roster: Character[]): LoreRate[] => {
|
|
11
11
|
const runnersUp = Object.keys(probabilities)
|
|
12
12
|
.filter((name) => name !== choice)
|
|
@@ -18,7 +18,6 @@ export const getLoreRates = ({ choice, probabilities }: ChoiceResponse, roster:
|
|
|
18
18
|
.slice(0, LORE_CHART_ROWS)
|
|
19
19
|
.map(({ name, probability }) => ({
|
|
20
20
|
displayName: findCharacterByName(roster, name)?.displayName ?? name,
|
|
21
|
-
name,
|
|
22
21
|
probability,
|
|
23
22
|
}));
|
|
24
23
|
};
|
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import type { Card } from "#src/models/Card";
|
|
2
|
-
import type { LoreRate } from "#src/models/LoreRate";
|
|
3
2
|
import type { SessionStartOutput } from "#src/models/SessionStartOutput";
|
|
4
3
|
|
|
5
|
-
import {
|
|
6
|
-
CHARACTER_LINE_PREFIX,
|
|
7
|
-
DEFAULT_LANGUAGE,
|
|
8
|
-
ELEMENT_LINE_PREFIX,
|
|
9
|
-
LORE_RATES_LINE_PREFIX,
|
|
10
|
-
NAMEPLATE_PREFIX,
|
|
11
|
-
RARITY_LINE_PREFIX,
|
|
12
|
-
} from "#src/services/constants";
|
|
4
|
+
import { DEFAULT_LANGUAGE, NAMEPLATE_PREFIX } from "#src/services/constants";
|
|
13
5
|
import { formatCard } from "#src/services/formatCard";
|
|
14
6
|
import { getReplyLanguageInstruction } from "#src/services/getReplyLanguageInstruction";
|
|
15
7
|
|
|
@@ -19,30 +11,18 @@ import { getReplyLanguageInstruction } from "#src/services/getReplyLanguageInstr
|
|
|
19
11
|
// Is a fact the model answers from. The reply language rides in the context rather than in the output style, which
|
|
20
12
|
// Is a file the plugin ships and cannot vary per person, and it is absent only when everything the model reads is
|
|
21
13
|
// English already — the reply language and the card's, which is the interface language's — so the common case
|
|
22
|
-
// Costs nothing and a card in another language never pulls the spoken lines into it.
|
|
23
|
-
// The character for a program — the agent console's Genshin theme — rather than for the model: its stars, and the
|
|
24
|
-
// Welcome chart's rows when the lore pick chose it, which the theme's rates panel shows
|
|
14
|
+
// Costs nothing and a card in another language never pulls the spoken lines into it.
|
|
25
15
|
export const getSessionStartOutput = (
|
|
26
16
|
card: Card,
|
|
27
17
|
remarks: string[],
|
|
28
18
|
replyLanguage: string,
|
|
29
19
|
interfaceLanguage: string,
|
|
30
|
-
loreRates: LoreRate[] = [],
|
|
31
20
|
): string => {
|
|
32
21
|
const isEnglishThroughout = replyLanguage === DEFAULT_LANGUAGE && interfaceLanguage === DEFAULT_LANGUAGE;
|
|
33
22
|
const instruction = isEnglishThroughout ? "" : getReplyLanguageInstruction(replyLanguage);
|
|
34
23
|
const output: SessionStartOutput = {
|
|
35
24
|
hookSpecificOutput: {
|
|
36
|
-
additionalContext: [
|
|
37
|
-
formatCard(card),
|
|
38
|
-
instruction,
|
|
39
|
-
`${CHARACTER_LINE_PREFIX}${card.name}`,
|
|
40
|
-
card.element ? `${ELEMENT_LINE_PREFIX}${card.element}` : "",
|
|
41
|
-
`${RARITY_LINE_PREFIX}${card.rarity}`,
|
|
42
|
-
loreRates.length > 0 ? `${LORE_RATES_LINE_PREFIX}${JSON.stringify(loreRates)}` : "",
|
|
43
|
-
]
|
|
44
|
-
.filter(Boolean)
|
|
45
|
-
.join("\n"),
|
|
25
|
+
additionalContext: [formatCard(card), instruction].filter(Boolean).join("\n"),
|
|
46
26
|
hookEventName: "SessionStart",
|
|
47
27
|
},
|
|
48
28
|
systemMessage: [`${NAMEPLATE_PREFIX}${card.headline}`, card.note, ...remarks, card.greeting]
|
|
@@ -8,19 +8,19 @@ import { getCharacterReference } from "#src/services/getCharacterReference";
|
|
|
8
8
|
import { readVolume } from "#src/services/readVolume";
|
|
9
9
|
|
|
10
10
|
// What a hook sends to be spoken or warmed: the character the session speaks as, with the reference the card or
|
|
11
|
-
// The generated map names for them, the dub the `voice` verb chose, the
|
|
12
|
-
//
|
|
11
|
+
// The generated map names for them, the dub the `voice` verb chose, the piece's markdown, where in the reply it sits
|
|
12
|
+
// And the volume as set
|
|
13
13
|
export const getSpeechRequest = (
|
|
14
14
|
type: SpeechRequest["type"],
|
|
15
15
|
name: string,
|
|
16
16
|
personaCard: PersonaCard | undefined,
|
|
17
17
|
language: VoiceLanguage,
|
|
18
|
-
|
|
18
|
+
markdown: string,
|
|
19
19
|
piece: ReplyPiece = TURNLESS_PIECE,
|
|
20
20
|
): SpeechRequest => ({
|
|
21
21
|
...piece,
|
|
22
22
|
language,
|
|
23
|
-
|
|
23
|
+
markdown,
|
|
24
24
|
name,
|
|
25
25
|
stem: getCharacterReference(name, personaCard),
|
|
26
26
|
type,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { checkIsReadable } from "#src/services/checkIsReadable";
|
|
2
|
+
import { collapseWhitespace } from "#src/services/collapseWhitespace";
|
|
3
|
+
import { getLineContent } from "#src/services/getLineContent";
|
|
4
|
+
|
|
5
|
+
// A spoken line may be a list item, so its marker is layout rather than words
|
|
6
|
+
const LIST_MARKER_REGEX = /^(?:[-+]|\d+\.)\s+/u;
|
|
7
|
+
const INLINE_CODE_REGEX = /`(?<code>[^`]*)`/gu;
|
|
8
|
+
const LINK_REGEX = /\[(?<text>[^\]]*)\]\([^)]*\)/gu;
|
|
9
|
+
const EMPHASIS_REGEX = /[*_~]{1,3}/gu;
|
|
10
|
+
// One line of a reply as it would be read out — the markup the style forbids stripped anyway — or nothing for a line
|
|
11
|
+
// That is not a spoken line or that the engine cannot read. The output style's one rule: a blockquote line is the
|
|
12
|
+
// Character's spoken line, and nothing else is written as one. Whether a line sits inside a fence is the reader's,
|
|
13
|
+
// Since it depends on the lines before it
|
|
14
|
+
export const getSpokenLine = (line: string): string | undefined => {
|
|
15
|
+
if (!line.trimStart().startsWith(">")) return undefined;
|
|
16
|
+
|
|
17
|
+
const spokenLine = collapseWhitespace(
|
|
18
|
+
getLineContent(line)
|
|
19
|
+
.replace(LIST_MARKER_REGEX, "")
|
|
20
|
+
.replaceAll(INLINE_CODE_REGEX, "$<code>")
|
|
21
|
+
.replaceAll(LINK_REGEX, "$<text>")
|
|
22
|
+
.replaceAll(EMPHASIS_REGEX, ""),
|
|
23
|
+
);
|
|
24
|
+
return checkIsReadable(spokenLine) ? spokenLine : undefined;
|
|
25
|
+
};
|
|
@@ -5,10 +5,10 @@ import { ViewerMoment as Moment } from "#src/models/ViewerMoment";
|
|
|
5
5
|
|
|
6
6
|
export interface ViewerReaction {
|
|
7
7
|
isExpressionCleared: boolean;
|
|
8
|
-
motion
|
|
8
|
+
motion: string;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
// What the viewer does at a moment: the motion the reader mapped to it,
|
|
11
|
+
// What the viewer does at a moment: the motion the reader mapped to it, "" for none, and the expression cleared when a
|
|
12
12
|
// Turn is over
|
|
13
13
|
export const getViewerReaction = (moment: ViewerMoment, motions: ViewerConfiguration["motions"]): ViewerReaction => ({
|
|
14
14
|
isExpressionCleared: moment === Moment.TurnEnd,
|
|
@@ -12,4 +12,4 @@ export const getWarmRequest = (
|
|
|
12
12
|
name: string,
|
|
13
13
|
personaCard: PersonaCard | undefined,
|
|
14
14
|
language: VoiceLanguage,
|
|
15
|
-
): SpeechRequest => getSpeechRequest(VoiceRequestType.Warm, name, personaCard, language,
|
|
15
|
+
): SpeechRequest => getSpeechRequest(VoiceRequestType.Warm, name, personaCard, language, `> ${WARM_TEXT}`);
|
|
@@ -9,7 +9,7 @@ import { parseJsonObject } from "#src/services/parseJsonObject";
|
|
|
9
9
|
// On the machine can write to, so every field is checked before the synthesizer acts on it. A line that is not
|
|
10
10
|
// JSON at all throws, and the server answers that as it answers any request that fails
|
|
11
11
|
export const parseVoiceRequest = (line: string): undefined | VoiceRequest => {
|
|
12
|
-
const { index, isFinal, language,
|
|
12
|
+
const { index, isFinal, language, markdown, messageId, name, stem, turnId, type, volume } = parseJsonObject(line);
|
|
13
13
|
if (type === VoiceRequestType.Stop) return { type };
|
|
14
14
|
if (
|
|
15
15
|
(type !== VoiceRequestType.Speak && type !== VoiceRequestType.Warm) ||
|
|
@@ -23,11 +23,10 @@ export const parseVoiceRequest = (line: string): undefined | VoiceRequest => {
|
|
|
23
23
|
typeof index !== "number" ||
|
|
24
24
|
!Number.isInteger(index) ||
|
|
25
25
|
index < 0 ||
|
|
26
|
-
|
|
27
|
-
!lines.every((item) => typeof item === "string") ||
|
|
26
|
+
typeof markdown !== "string" ||
|
|
28
27
|
typeof volume !== "number" ||
|
|
29
28
|
!checkIsVolume(String(volume))
|
|
30
29
|
)
|
|
31
30
|
return undefined;
|
|
32
|
-
else return { index, isFinal, language,
|
|
31
|
+
else return { index, isFinal, language, markdown, messageId, name, stem, turnId, type, volume };
|
|
33
32
|
};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { ViewerConfiguration } from "#src/models/ViewerConfiguration";
|
|
2
2
|
|
|
3
3
|
import { ViewerMoments } from "#src/models/ViewerMoment";
|
|
4
|
+
import { EMPTY_VIEWER_MOTIONS } from "#src/services/constants";
|
|
4
5
|
|
|
5
6
|
export const readMotions = (motions: unknown): ViewerConfiguration["motions"] => {
|
|
6
|
-
|
|
7
|
+
const result = { ...EMPTY_VIEWER_MOTIONS };
|
|
8
|
+
if (typeof motions !== "object" || motions === null) return result;
|
|
7
9
|
|
|
8
|
-
const result: ViewerConfiguration["motions"] = {};
|
|
9
10
|
for (const moment of ViewerMoments) {
|
|
10
11
|
const motion: unknown = Reflect.get(motions, moment);
|
|
11
|
-
if (typeof motion === "string"
|
|
12
|
+
if (typeof motion === "string") result[moment] = motion;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
return result;
|
|
@@ -48,7 +48,6 @@ export const readRoster = (language: string): Character[] => {
|
|
|
48
48
|
displayName: localized.name,
|
|
49
49
|
element: character.elementText,
|
|
50
50
|
name: character.name,
|
|
51
|
-
rarity: character.rarity,
|
|
52
51
|
region: localized.region,
|
|
53
52
|
title: localized.title,
|
|
54
53
|
version: character.version,
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { ViewerConfiguration } from "#src/models/ViewerConfiguration";
|
|
2
2
|
import type { ViewerLink } from "#src/models/ViewerLink";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
EMPTY_VIEWER_MOTIONS,
|
|
6
|
+
VIEWER_DEFAULT_FRAME_COLOR,
|
|
7
|
+
VIEWER_PROOF_DURATION_MS,
|
|
8
|
+
VIEWER_TEXT_COLOR,
|
|
9
|
+
} from "#src/services/constants";
|
|
5
10
|
|
|
6
11
|
export interface SetViewerDependencies {
|
|
7
12
|
connect: (address: string) => Promise<undefined | ViewerLink>;
|
|
@@ -21,7 +26,7 @@ export const setViewer = async (
|
|
|
21
26
|
if (!link) return false;
|
|
22
27
|
|
|
23
28
|
link.bubble(modelId, proofText, VIEWER_PROOF_DURATION_MS, VIEWER_DEFAULT_FRAME_COLOR, VIEWER_TEXT_COLOR);
|
|
24
|
-
writeConfiguration({ address, modelId, motions: readConfiguration()?.motions ??
|
|
29
|
+
writeConfiguration({ address, modelId, motions: readConfiguration()?.motions ?? EMPTY_VIEWER_MOTIONS });
|
|
25
30
|
link.close();
|
|
26
31
|
return true;
|
|
27
32
|
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { checkIsReadable } from "#src/services/checkIsReadable";
|
|
2
|
-
import { collapseWhitespace } from "#src/services/collapseWhitespace";
|
|
3
|
-
|
|
4
|
-
// The closing fence is optional so a piece cut mid-block drops the rest of it too, rather than reading code aloud
|
|
5
|
-
const FENCED_CODE_REGEX = /```[\s\S]*?(?:```|$)/gu;
|
|
6
|
-
// The output style's one rule: a blockquote line is the character's spoken line, and nothing else is written as one
|
|
7
|
-
const SPOKEN_LINE_REGEX = /^\s*>\s?(?<line>.*)$/u;
|
|
8
|
-
// A spoken line may be a list item, so its marker is layout rather than words
|
|
9
|
-
const LIST_MARKER_REGEX = /^(?:[-+]|\d+\.)\s+/u;
|
|
10
|
-
const INLINE_CODE_REGEX = /`(?<code>[^`]*)`/gu;
|
|
11
|
-
const LINK_REGEX = /\[(?<text>[^\]]*)\]\([^)]*\)/gu;
|
|
12
|
-
const EMPHASIS_REGEX = /[*_~]{1,3}/gu;
|
|
13
|
-
// The spoken lines in a piece of a reply, as they would be read out — the markup the style forbids stripped
|
|
14
|
-
// Anyway, and only the lines the engine can read, gated here so a piece with none never wakes it. Stateless on
|
|
15
|
-
// Purpose: the tool flushes a reply at line breaks, so a spoken line arrives whole in one piece
|
|
16
|
-
export const getSpokenLines = (markdown: string): string[] =>
|
|
17
|
-
markdown
|
|
18
|
-
.replaceAll(FENCED_CODE_REGEX, "")
|
|
19
|
-
.split("\n")
|
|
20
|
-
.map((line) =>
|
|
21
|
-
collapseWhitespace(
|
|
22
|
-
(SPOKEN_LINE_REGEX.exec(line)?.groups?.line ?? "")
|
|
23
|
-
.replace(LIST_MARKER_REGEX, "")
|
|
24
|
-
.replaceAll(INLINE_CODE_REGEX, "$<code>")
|
|
25
|
-
.replaceAll(LINK_REGEX, "$<text>")
|
|
26
|
-
.replaceAll(EMPHASIS_REGEX, ""),
|
|
27
|
-
),
|
|
28
|
-
)
|
|
29
|
-
.filter((line) => checkIsReadable(line));
|