@waifucave/discord-waifus 1.5.154
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/LICENSE +21 -0
- package/README.md +230 -0
- package/THIRD_PARTY_NOTICES.md +26 -0
- package/assets/ocr/eng.traineddata +0 -0
- package/bin/waifus.mjs +36 -0
- package/dist/api/errors.d.ts +9 -0
- package/dist/api/errors.js +23 -0
- package/dist/api/errors.js.map +1 -0
- package/dist/api/server.d.ts +19 -0
- package/dist/api/server.js +1290 -0
- package/dist/api/server.js.map +1 -0
- package/dist/backend/logger.d.ts +20 -0
- package/dist/backend/logger.js +65 -0
- package/dist/backend/logger.js.map +1 -0
- package/dist/backend/migrations.d.ts +4 -0
- package/dist/backend/migrations.js +521 -0
- package/dist/backend/migrations.js.map +1 -0
- package/dist/backend/redaction.d.ts +1 -0
- package/dist/backend/redaction.js +22 -0
- package/dist/backend/redaction.js.map +1 -0
- package/dist/backend/runtime.d.ts +30 -0
- package/dist/backend/runtime.js +49 -0
- package/dist/backend/runtime.js.map +1 -0
- package/dist/backend/server.d.ts +18 -0
- package/dist/backend/server.js +581 -0
- package/dist/backend/server.js.map +1 -0
- package/dist/cli/commands.d.ts +35 -0
- package/dist/cli/commands.js +510 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/main.d.ts +1 -0
- package/dist/cli/main.js +12 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/parser.d.ts +10 -0
- package/dist/cli/parser.js +64 -0
- package/dist/cli/parser.js.map +1 -0
- package/dist/config/appConfig.d.ts +3 -0
- package/dist/config/appConfig.js +27 -0
- package/dist/config/appConfig.js.map +1 -0
- package/dist/config/layout.d.ts +13 -0
- package/dist/config/layout.js +173 -0
- package/dist/config/layout.js.map +1 -0
- package/dist/config/paths.d.ts +5 -0
- package/dist/config/paths.js +20 -0
- package/dist/config/paths.js.map +1 -0
- package/dist/config/prebuiltWaifus.d.ts +3 -0
- package/dist/config/prebuiltWaifus.js +106 -0
- package/dist/config/prebuiltWaifus.js.map +1 -0
- package/dist/discord/client.d.ts +394 -0
- package/dist/discord/client.js +1196 -0
- package/dist/discord/client.js.map +1 -0
- package/dist/discord/contextBuilder.d.ts +15 -0
- package/dist/discord/contextBuilder.js +18 -0
- package/dist/discord/contextBuilder.js.map +1 -0
- package/dist/discord/intents.d.ts +5 -0
- package/dist/discord/intents.js +21 -0
- package/dist/discord/intents.js.map +1 -0
- package/dist/discord/memberCache.d.ts +12 -0
- package/dist/discord/memberCache.js +55 -0
- package/dist/discord/memberCache.js.map +1 -0
- package/dist/discord/normalization.d.ts +34 -0
- package/dist/discord/normalization.js +330 -0
- package/dist/discord/normalization.js.map +1 -0
- package/dist/discord/rateLimit.d.ts +9 -0
- package/dist/discord/rateLimit.js +11 -0
- package/dist/discord/rateLimit.js.map +1 -0
- package/dist/orchestration/context.d.ts +85 -0
- package/dist/orchestration/context.js +200 -0
- package/dist/orchestration/context.js.map +1 -0
- package/dist/orchestration/decisions.d.ts +52 -0
- package/dist/orchestration/decisions.js +61 -0
- package/dist/orchestration/decisions.js.map +1 -0
- package/dist/orchestration/messageSplit.d.ts +6 -0
- package/dist/orchestration/messageSplit.js +118 -0
- package/dist/orchestration/messageSplit.js.map +1 -0
- package/dist/orchestration/ocr.d.ts +43 -0
- package/dist/orchestration/ocr.js +504 -0
- package/dist/orchestration/ocr.js.map +1 -0
- package/dist/orchestration/ocrPackages.d.ts +24 -0
- package/dist/orchestration/ocrPackages.js +85 -0
- package/dist/orchestration/ocrPackages.js.map +1 -0
- package/dist/orchestration/promptBlocks.d.ts +28 -0
- package/dist/orchestration/promptBlocks.js +232 -0
- package/dist/orchestration/promptBlocks.js.map +1 -0
- package/dist/orchestration/replyQuote.d.ts +7 -0
- package/dist/orchestration/replyQuote.js +198 -0
- package/dist/orchestration/replyQuote.js.map +1 -0
- package/dist/orchestration/reviewer.d.ts +5 -0
- package/dist/orchestration/reviewer.js +5 -0
- package/dist/orchestration/reviewer.js.map +1 -0
- package/dist/orchestration/runtime.d.ts +152 -0
- package/dist/orchestration/runtime.js +3535 -0
- package/dist/orchestration/runtime.js.map +1 -0
- package/dist/orchestration/session.d.ts +30 -0
- package/dist/orchestration/session.js +41 -0
- package/dist/orchestration/session.js.map +1 -0
- package/dist/orchestration/stageManager.d.ts +42 -0
- package/dist/orchestration/stageManager.js +50 -0
- package/dist/orchestration/stageManager.js.map +1 -0
- package/dist/providers/catalog.d.ts +6 -0
- package/dist/providers/catalog.js +212 -0
- package/dist/providers/catalog.js.map +1 -0
- package/dist/providers/pipelines.d.ts +13 -0
- package/dist/providers/pipelines.js +2388 -0
- package/dist/providers/pipelines.js.map +1 -0
- package/dist/providers/types.d.ts +91 -0
- package/dist/providers/types.js +2 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/shared/queryLog.d.ts +39 -0
- package/dist/shared/queryLog.js +80 -0
- package/dist/shared/queryLog.js.map +1 -0
- package/dist/shared/schemas/common.d.ts +21 -0
- package/dist/shared/schemas/common.js +27 -0
- package/dist/shared/schemas/common.js.map +1 -0
- package/dist/shared/schemas/config.d.ts +57 -0
- package/dist/shared/schemas/config.js +49 -0
- package/dist/shared/schemas/config.js.map +1 -0
- package/dist/shared/schemas/domain.d.ts +825 -0
- package/dist/shared/schemas/domain.js +444 -0
- package/dist/shared/schemas/domain.js.map +1 -0
- package/dist/storage/atomic.d.ts +6 -0
- package/dist/storage/atomic.js +60 -0
- package/dist/storage/atomic.js.map +1 -0
- package/dist/storage/errors.d.ts +12 -0
- package/dist/storage/errors.js +23 -0
- package/dist/storage/errors.js.map +1 -0
- package/dist/storage/locks.d.ts +9 -0
- package/dist/storage/locks.js +42 -0
- package/dist/storage/locks.js.map +1 -0
- package/dist/storage/storageService.d.ts +25 -0
- package/dist/storage/storageService.js +66 -0
- package/dist/storage/storageService.js.map +1 -0
- package/dist-frontend/assets/index-B2bB3_2r.js +39 -0
- package/dist-frontend/assets/index-B2bB3_2r.js.map +1 -0
- package/dist-frontend/assets/index-Dj1L8Px-.css +1 -0
- package/dist-frontend/index.html +14 -0
- package/docs/api.md +162 -0
- package/docs/old-orchestrator-prompt.md +123 -0
- package/package.json +81 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { WaifuPromptLayout } from "../shared/schemas/domain.js";
|
|
2
|
+
export type PromptBlockContext = {
|
|
3
|
+
waifuTag: string;
|
|
4
|
+
displayName: string;
|
|
5
|
+
personalityContent: string;
|
|
6
|
+
scheduleContent: string;
|
|
7
|
+
toolUseInstructions: string | undefined;
|
|
8
|
+
activeParticipantDisplayNames: string[];
|
|
9
|
+
emojiList: string;
|
|
10
|
+
memoryLines: string[];
|
|
11
|
+
currentlyDoing: string | undefined;
|
|
12
|
+
sceneDirection: string | undefined;
|
|
13
|
+
};
|
|
14
|
+
export type WaifuPromptSection = "top" | "mid" | "trailing";
|
|
15
|
+
export type WaifuPromptBlockDef = {
|
|
16
|
+
id: string;
|
|
17
|
+
defaultSection: WaifuPromptSection;
|
|
18
|
+
render: (ctx: PromptBlockContext) => string | undefined;
|
|
19
|
+
};
|
|
20
|
+
export declare const WAIFU_PROMPT_BLOCKS: WaifuPromptBlockDef[];
|
|
21
|
+
export declare function promptTagName(value: string): string;
|
|
22
|
+
export declare function resolveGroupTag(tag: string, waifuTag: string): string;
|
|
23
|
+
export declare function assembleWaifuPrompt(layout: WaifuPromptLayout, ctx: PromptBlockContext): {
|
|
24
|
+
systemPrompt: string;
|
|
25
|
+
midSystemBlock: string;
|
|
26
|
+
trailingSystemBlock: string;
|
|
27
|
+
};
|
|
28
|
+
export declare function reconcileWaifuPromptLayout(layout: WaifuPromptLayout): WaifuPromptLayout;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// --- Fixed block wording (copied verbatim from the historical buildWaifuPromptParts) ----------
|
|
2
|
+
const INPUT_FORMAT = [
|
|
3
|
+
"Each incoming message in this conversation arrives in a chat-transcript shape so you can read Discord context:",
|
|
4
|
+
"An optional `replying to > Author: preview` line appears first when the message is replying to an earlier one. The next line is `DisplayName: <body>` (the body may continue on additional lines). Optional `[attachments: Nx image]` and `[image_text: ...]` lines may follow, one per image with extracted text.",
|
|
5
|
+
"The `replying to > Author: ...` line, the `DisplayName:` prefix, and any bracketed lines are framing only. They are not part of what the speaker actually wrote, and they are not how Discord messages look."
|
|
6
|
+
].join("\n");
|
|
7
|
+
const REPLY_TARGETING = [
|
|
8
|
+
"To reply to one specific earlier message, you may start your reply with a single `replying to > Author: text-of-that-message` line. Copy the message text as closely as you can (small differences are fine; the runtime fuzzy-matches it). Put your actual reply on the next line.",
|
|
9
|
+
"If you only know the speaker, write `replying to > Author`; the runtime targets that speaker's most recent message.",
|
|
10
|
+
"The `replying to >` line is not sent to Discord; it only tells the runtime which message your reply targets.",
|
|
11
|
+
"Use this instead of pinging when you want to address one specific earlier message. Otherwise omit the quote entirely and just write your reply.",
|
|
12
|
+
"Quote example - to reply specifically to Kevin's earlier `what's the weather like?` message, write:\n replying to > Kevin: what's the weather like?\n sunny and warm\nThe runtime consumes the `replying to > Kevin: ...` line to set Discord's reply target; only `sunny and warm` is sent."
|
|
13
|
+
].join("\n");
|
|
14
|
+
const MENTION_POLICY = [
|
|
15
|
+
"To ping a user, write <@DisplayName> - where `DisplayName` is copied verbatim from the `DisplayName:` prefix on one of their messages. Example: a message that starts with `Kevin: hey` is pinged as <@Kevin>.",
|
|
16
|
+
"Do not ping a user who is already active in the recent chat or who just spoke. Mention their display name in plain text instead.",
|
|
17
|
+
"Only ping when you are reviving an older missed message, pulling back someone who has gone quiet, or a scene_direction explicitly asks for a ping."
|
|
18
|
+
].join("\n");
|
|
19
|
+
const STYLE_CONSTRAINTS = [
|
|
20
|
+
"Write exactly one short phrase or one very short sentence, usually under 12 words.",
|
|
21
|
+
"Never write a second sentence.",
|
|
22
|
+
"This length rule overrides your persona, reply_style, and scene_direction. Even when asked for a longer or more thoughtful reply, compress it to one tiny conversational beat.",
|
|
23
|
+
"Avoid stacked clauses, multi-line replies, setup-plus-punchline chains, and explanations. A sharp fragment is usually stronger than a complete mini speech."
|
|
24
|
+
].join("\n");
|
|
25
|
+
const HARD_RULES = [
|
|
26
|
+
"Your reply is the raw message body that will be sent verbatim to Discord.",
|
|
27
|
+
"Your turn is exactly one Discord message body, never a transcript.",
|
|
28
|
+
"Do not write `Name: ...` or `DisplayName: ...` lines for any character, including yourself and every other waifu in the channel.",
|
|
29
|
+
"Do not draft another waifu's reply. If you find yourself doing that, stop and write only your own message.",
|
|
30
|
+
"Do not include bracketed metadata tags: no `[attachments: ...]`, no `[image_text: ...]`, no `[replying to: ...]`, no `[timestamp: ...]`, no `[reactions: ...]`, no `[index: ...]`, no `[scene_direction: ...]`, and no other `[tag: value]` constructions.",
|
|
31
|
+
"Do not begin with your own display name followed by a colon. Other than the optional leading `replying to > Author: ...` reply-targeting line, begin with the first word you are actually saying.",
|
|
32
|
+
"Do not echo or paraphrase any prior message's bracketed framing tags.",
|
|
33
|
+
"Do not output physical actions, roleplay narration, or stage directions. No asterisks-wrapped actions like *smiles* or *waves*, no parenthetical stage notes like (hugs them), and no bracketed cues like [walks over].",
|
|
34
|
+
"The optional leading `replying to > Author: ...` reply-targeting line is the only allowed prefix exception.",
|
|
35
|
+
"Never use raw Discord IDs for pings.",
|
|
36
|
+
"Use only listed server emojis."
|
|
37
|
+
].join("\n");
|
|
38
|
+
const ENVIRONMENT_RULES = [
|
|
39
|
+
"You are chatting in a live Discord text channel — this is a real chat room with real users, not a roleplay scene, story, or chat fiction.",
|
|
40
|
+
"Write one Discord-safe message per turn.",
|
|
41
|
+
"Reply with only what you would actually type into a chat box — no narration, no meta commentary, no describing yourself in the third person."
|
|
42
|
+
].join("\n");
|
|
43
|
+
const DIRECTOR_NOTES = [
|
|
44
|
+
"Keep your reply short.",
|
|
45
|
+
"Do not repeat what the previous waifu just said.",
|
|
46
|
+
"Do not repeat a person's name when recent context already makes the target clear.",
|
|
47
|
+
"To pull a quiet person back in, use their <@Name> tag instead of repeating their name; do not tag them again if anyone already tagged them recently."
|
|
48
|
+
].join("\n");
|
|
49
|
+
// --- Block registry ----------------------------------------------------------------------------
|
|
50
|
+
export const WAIFU_PROMPT_BLOCKS = [
|
|
51
|
+
{
|
|
52
|
+
id: "identity",
|
|
53
|
+
defaultSection: "top",
|
|
54
|
+
render: (ctx) => `<${ctx.waifuTag}_identity>\nYou are acting as ${ctx.displayName} in a discord server together with real people and other waifus\n</${ctx.waifuTag}_identity>`
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: "personality",
|
|
58
|
+
defaultSection: "top",
|
|
59
|
+
render: (ctx) => `<${ctx.waifuTag}_personality>\n${ctx.personalityContent}\n</${ctx.waifuTag}_personality>`
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: "schedule",
|
|
63
|
+
defaultSection: "top",
|
|
64
|
+
render: (ctx) => `<${ctx.waifuTag}_shedule>\n${ctx.scheduleContent}\n</${ctx.waifuTag}_shedule>`
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: "contextStructure",
|
|
68
|
+
defaultSection: "top",
|
|
69
|
+
render: () => `<context_message_structure>\n${INPUT_FORMAT}\n</context_message_structure>`
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: "environment",
|
|
73
|
+
defaultSection: "top",
|
|
74
|
+
render: () => `<environment_instructions>\n${ENVIRONMENT_RULES}\n</environment_instructions>`
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: "replyTargeting",
|
|
78
|
+
defaultSection: "top",
|
|
79
|
+
render: () => `<replying_to_message>\n${REPLY_TARGETING}\n</replying_to_message>`
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
id: "mentionPolicy",
|
|
83
|
+
defaultSection: "top",
|
|
84
|
+
render: () => `<mention_policy>\n${MENTION_POLICY}\n</mention_policy>`
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: "styleConstraints",
|
|
88
|
+
defaultSection: "top",
|
|
89
|
+
render: () => `<style_constraints>\n${STYLE_CONSTRAINTS}\n</style_constraints>`
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: "hardRules",
|
|
93
|
+
defaultSection: "top",
|
|
94
|
+
render: () => `<hard_rules>\n${HARD_RULES}\n</hard_rules>`
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: "toolUse",
|
|
98
|
+
defaultSection: "top",
|
|
99
|
+
// Content is gated upstream by waifu.tools.toolUse / model.supportsTools / active server
|
|
100
|
+
// tools; when there is nothing to say, toolUseInstructions is undefined and the block drops.
|
|
101
|
+
render: (ctx) => (ctx.toolUseInstructions ? `<tool_use>\n${ctx.toolUseInstructions}\n</tool_use>` : undefined)
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
id: "directorNotes",
|
|
105
|
+
defaultSection: "mid",
|
|
106
|
+
render: () => `<director_notes>\n${DIRECTOR_NOTES}\n</director_notes>`
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: "activeParticipants",
|
|
110
|
+
defaultSection: "mid",
|
|
111
|
+
render: (ctx) => `<active_chat_participants>\n${ctx.activeParticipantDisplayNames.length
|
|
112
|
+
? ctx.activeParticipantDisplayNames.map((displayName) => `- ${displayName}`).join("\n")
|
|
113
|
+
: "(none)"}\n</active_chat_participants>`
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
id: "serverEmojis",
|
|
117
|
+
defaultSection: "mid",
|
|
118
|
+
render: (ctx) => `<server_emojis>\n${ctx.emojiList || "(none cached)"}\n</server_emojis>`
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: "relevantMemories",
|
|
122
|
+
defaultSection: "trailing",
|
|
123
|
+
render: (ctx) => ctx.memoryLines.length
|
|
124
|
+
? `<${ctx.waifuTag}_relevant_memories>\n${ctx.memoryLines.join("\n")}\n</${ctx.waifuTag}_relevant_memories>`
|
|
125
|
+
: undefined
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
// The optional trailing personality reminder. Distinct id from `personality` so each layout
|
|
129
|
+
// node has exactly one home even though both render the same content.
|
|
130
|
+
id: "personalityReminder",
|
|
131
|
+
defaultSection: "trailing",
|
|
132
|
+
render: (ctx) => `<${ctx.waifuTag}_personality>\n${ctx.personalityContent}\n</${ctx.waifuTag}_personality>`
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
id: "currentlyDoing",
|
|
136
|
+
defaultSection: "trailing",
|
|
137
|
+
render: (ctx) => (ctx.currentlyDoing ? `<currently_doing>${ctx.currentlyDoing}</currently_doing>` : undefined)
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
id: "sceneDirection",
|
|
141
|
+
defaultSection: "trailing",
|
|
142
|
+
render: (ctx) => (ctx.sceneDirection ? `<scene_direction>${ctx.sceneDirection}</scene_direction>` : undefined)
|
|
143
|
+
}
|
|
144
|
+
];
|
|
145
|
+
const BLOCK_BY_ID = new Map(WAIFU_PROMPT_BLOCKS.map((block) => [block.id, block]));
|
|
146
|
+
// --- Tag helpers -------------------------------------------------------------------------------
|
|
147
|
+
// Normalize an arbitrary string into a safe XML-ish tag name. Shared by the waifu tag and by
|
|
148
|
+
// user-created group tags so both follow the same rules.
|
|
149
|
+
export function promptTagName(value) {
|
|
150
|
+
const normalized = value
|
|
151
|
+
.trim()
|
|
152
|
+
.toLowerCase()
|
|
153
|
+
.replace(/[^a-z0-9_-]+/g, "_")
|
|
154
|
+
.replace(/^_+|_+$/g, "");
|
|
155
|
+
return /^[a-z]/.test(normalized) ? normalized : `waifu_${normalized || "unknown"}`;
|
|
156
|
+
}
|
|
157
|
+
// Resolve a group's stored tag template (which may contain the `{name}` token) into the final
|
|
158
|
+
// sanitized tag for a given waifu.
|
|
159
|
+
export function resolveGroupTag(tag, waifuTag) {
|
|
160
|
+
return promptTagName(tag.replace(/\{name\}/g, waifuTag));
|
|
161
|
+
}
|
|
162
|
+
// --- Assembly ----------------------------------------------------------------------------------
|
|
163
|
+
function renderBlock(blockId, ctx) {
|
|
164
|
+
return BLOCK_BY_ID.get(blockId)?.render(ctx);
|
|
165
|
+
}
|
|
166
|
+
function renderNode(node, ctx) {
|
|
167
|
+
if (!node.enabled)
|
|
168
|
+
return undefined;
|
|
169
|
+
if (node.kind === "block") {
|
|
170
|
+
return renderBlock(node.blockId, ctx);
|
|
171
|
+
}
|
|
172
|
+
const childParts = [];
|
|
173
|
+
for (const child of node.children) {
|
|
174
|
+
if (!child.enabled)
|
|
175
|
+
continue;
|
|
176
|
+
const out = renderBlock(child.blockId, ctx);
|
|
177
|
+
if (out)
|
|
178
|
+
childParts.push(out);
|
|
179
|
+
}
|
|
180
|
+
if (childParts.length === 0)
|
|
181
|
+
return undefined;
|
|
182
|
+
const tag = resolveGroupTag(node.tag, ctx.waifuTag);
|
|
183
|
+
return `<${tag}>\n${childParts.join("\n")}\n</${tag}>`;
|
|
184
|
+
}
|
|
185
|
+
function renderSection(nodes, ctx) {
|
|
186
|
+
const parts = [];
|
|
187
|
+
for (const node of nodes) {
|
|
188
|
+
const out = renderNode(node, ctx);
|
|
189
|
+
if (out)
|
|
190
|
+
parts.push(out);
|
|
191
|
+
}
|
|
192
|
+
return parts.join("\n");
|
|
193
|
+
}
|
|
194
|
+
// Walk the layout and build the three message-array strings. The slot→string mapping
|
|
195
|
+
// (top→systemPrompt, mid→midSystemBlock, trailing→trailingSystemBlock) is fixed; only the
|
|
196
|
+
// composition of each is data-driven.
|
|
197
|
+
export function assembleWaifuPrompt(layout, ctx) {
|
|
198
|
+
return {
|
|
199
|
+
systemPrompt: renderSection(layout.top, ctx),
|
|
200
|
+
midSystemBlock: renderSection(layout.mid, ctx),
|
|
201
|
+
trailingSystemBlock: renderSection(layout.trailing, ctx)
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
// Append any registry block missing from the stored layout to its default section (disabled), so
|
|
205
|
+
// that adding a new block to the registry later never makes it invisible to existing waifus.
|
|
206
|
+
export function reconcileWaifuPromptLayout(layout) {
|
|
207
|
+
const present = new Set();
|
|
208
|
+
const collect = (nodes) => {
|
|
209
|
+
for (const node of nodes) {
|
|
210
|
+
if (node.kind === "block")
|
|
211
|
+
present.add(node.blockId);
|
|
212
|
+
else
|
|
213
|
+
for (const child of node.children)
|
|
214
|
+
present.add(child.blockId);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
collect(layout.top);
|
|
218
|
+
collect(layout.mid);
|
|
219
|
+
collect(layout.trailing);
|
|
220
|
+
const next = {
|
|
221
|
+
top: [...layout.top],
|
|
222
|
+
mid: [...layout.mid],
|
|
223
|
+
trailing: [...layout.trailing]
|
|
224
|
+
};
|
|
225
|
+
for (const def of WAIFU_PROMPT_BLOCKS) {
|
|
226
|
+
if (present.has(def.id))
|
|
227
|
+
continue;
|
|
228
|
+
next[def.defaultSection].push({ kind: "block", blockId: def.id, enabled: false });
|
|
229
|
+
}
|
|
230
|
+
return next;
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=promptBlocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promptBlocks.js","sourceRoot":"","sources":["../../src/orchestration/promptBlocks.ts"],"names":[],"mappings":"AA8BA,iGAAiG;AAEjG,MAAM,YAAY,GAAG;IACnB,gHAAgH;IAChH,oTAAoT;IACpT,8MAA8M;CAC/M,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,MAAM,eAAe,GAAG;IACtB,qRAAqR;IACrR,qHAAqH;IACrH,8GAA8G;IAC9G,iJAAiJ;IACjJ,gSAAgS;CACjS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,MAAM,cAAc,GAAG;IACrB,gNAAgN;IAChN,kIAAkI;IAClI,oJAAoJ;CACrJ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,MAAM,iBAAiB,GAAG;IACxB,oFAAoF;IACpF,gCAAgC;IAChC,gLAAgL;IAChL,6JAA6J;CAC9J,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,MAAM,U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ACzB,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO;gBAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;;gBAChD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ;oBAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrE,CAAC;IACH,CAAC,CAAC;IACF,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACpB,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACpB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAEzB,MAAM,IAAI,GAAsB;QAC9B,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC;QACpB,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC;QACpB,QAAQ,EAAE,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC;KAC/B,CAAC;IACF,KAAK,MAAM,GAAG,IAAI,mBAAmB,EAAE,CAAC;QACtC,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,SAAS;QAClC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IACpF,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ContextMessage } from "./context.js";
|
|
2
|
+
export type ReplyQuoteExtraction = {
|
|
3
|
+
replyToMessageId: string | undefined;
|
|
4
|
+
cleanedContent: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function extractReplyQuote(content: string, candidates: ContextMessage[]): ReplyQuoteExtraction;
|
|
7
|
+
export declare function normalizeForMatch(input: string): string;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
const QUOTE_LINE_RE = /^[ \t]*>(?!>)[ \t]?(.*)$/;
|
|
2
|
+
const REPLYING_TO_QUOTE_LINE_RE = /^[ \t]*replying[ \t]+to[ \t]*>[ \t]?(.*)$/i;
|
|
3
|
+
const AUTHOR_BODY_RE = /^[ \t]*([^:\n]{1,40}):[ \t]*(.+)$/;
|
|
4
|
+
const IMPLICIT_QUOTE_LINE_RE = /^[ \t]*([^:\n]{1,40}):[ \t]+(.+)$/;
|
|
5
|
+
const JACCARD_THRESHOLD = 0.6;
|
|
6
|
+
export function extractReplyQuote(content, candidates) {
|
|
7
|
+
const lines = content.split("\n");
|
|
8
|
+
const quoteBodies = [];
|
|
9
|
+
let cursor = 0;
|
|
10
|
+
while (cursor < lines.length) {
|
|
11
|
+
const match = lines[cursor].match(REPLYING_TO_QUOTE_LINE_RE) ?? lines[cursor].match(QUOTE_LINE_RE);
|
|
12
|
+
if (!match)
|
|
13
|
+
break;
|
|
14
|
+
quoteBodies.push(match[1]);
|
|
15
|
+
cursor += 1;
|
|
16
|
+
}
|
|
17
|
+
if (quoteBodies.length === 0) {
|
|
18
|
+
const embedded = tryEmbeddedReplyQuote(lines, candidates);
|
|
19
|
+
if (embedded)
|
|
20
|
+
return embedded;
|
|
21
|
+
const implicit = tryImplicitQuote(content, candidates);
|
|
22
|
+
if (implicit)
|
|
23
|
+
return implicit;
|
|
24
|
+
return { replyToMessageId: undefined, cleanedContent: content };
|
|
25
|
+
}
|
|
26
|
+
const cleanedContent = lines.slice(cursor).join("\n").replace(/^\s+/, "");
|
|
27
|
+
const replyToMessageId = resolveQuoteTarget(quoteBodies.join("\n"), candidates);
|
|
28
|
+
return { replyToMessageId: replyToMessageId?.id, cleanedContent };
|
|
29
|
+
}
|
|
30
|
+
function tryEmbeddedReplyQuote(lines, candidates) {
|
|
31
|
+
const quoteIndex = lines.findIndex((line, index) => index > 0 && REPLYING_TO_QUOTE_LINE_RE.test(line));
|
|
32
|
+
if (quoteIndex < 0)
|
|
33
|
+
return null;
|
|
34
|
+
const match = lines[quoteIndex].match(REPLYING_TO_QUOTE_LINE_RE);
|
|
35
|
+
if (!match)
|
|
36
|
+
return null;
|
|
37
|
+
const before = trimBlankLines(lines.slice(0, quoteIndex)).join("\n");
|
|
38
|
+
const after = trimBlankLines(lines.slice(quoteIndex + 1)).join("\n");
|
|
39
|
+
const cleanedContent = before && after && before.trim() === after.trim()
|
|
40
|
+
? before
|
|
41
|
+
: [before, after].filter(Boolean).join("\n");
|
|
42
|
+
const replyToMessageId = resolveQuoteTarget(match[1], candidates);
|
|
43
|
+
return {
|
|
44
|
+
replyToMessageId: replyToMessageId?.id,
|
|
45
|
+
cleanedContent
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function tryImplicitQuote(content, candidates) {
|
|
49
|
+
const lines = content.split("\n");
|
|
50
|
+
let firstIdx = 0;
|
|
51
|
+
while (firstIdx < lines.length && lines[firstIdx].trim() === "")
|
|
52
|
+
firstIdx += 1;
|
|
53
|
+
if (firstIdx >= lines.length)
|
|
54
|
+
return null;
|
|
55
|
+
if (/^[ \t]*>/.test(lines[firstIdx]))
|
|
56
|
+
return null;
|
|
57
|
+
const match = lines[firstIdx].match(IMPLICIT_QUOTE_LINE_RE);
|
|
58
|
+
if (!match)
|
|
59
|
+
return tryImplicitContentQuote(lines, firstIdx, candidates);
|
|
60
|
+
const authorName = match[1];
|
|
61
|
+
const body = match[2];
|
|
62
|
+
const tokenCount = matchTokenCount(body);
|
|
63
|
+
if (tokenCount < 2)
|
|
64
|
+
return null;
|
|
65
|
+
const matched = findBestMatch(body, candidates, authorName, {
|
|
66
|
+
allowContainment: tokenCount >= 3,
|
|
67
|
+
allowJaccard: false
|
|
68
|
+
});
|
|
69
|
+
if (!matched)
|
|
70
|
+
return null;
|
|
71
|
+
const cleanedContent = [...lines.slice(0, firstIdx), ...lines.slice(firstIdx + 1)]
|
|
72
|
+
.join("\n")
|
|
73
|
+
.replace(/^\s+/, "");
|
|
74
|
+
return { replyToMessageId: matched.id, cleanedContent };
|
|
75
|
+
}
|
|
76
|
+
function tryImplicitContentQuote(lines, firstIdx, candidates) {
|
|
77
|
+
if (lines.slice(firstIdx + 1).every((line) => line.trim() === ""))
|
|
78
|
+
return null;
|
|
79
|
+
const body = lines[firstIdx].trim();
|
|
80
|
+
const tokenCount = matchTokenCount(body);
|
|
81
|
+
if (tokenCount < 2)
|
|
82
|
+
return null;
|
|
83
|
+
const matched = findBestMatch(body, candidates, undefined, {
|
|
84
|
+
allowContainment: tokenCount >= 3,
|
|
85
|
+
allowJaccard: false
|
|
86
|
+
});
|
|
87
|
+
if (!matched)
|
|
88
|
+
return null;
|
|
89
|
+
if (matched.id === candidates.at(-1)?.id)
|
|
90
|
+
return null;
|
|
91
|
+
const cleanedContent = [...lines.slice(0, firstIdx), ...lines.slice(firstIdx + 1)]
|
|
92
|
+
.join("\n")
|
|
93
|
+
.replace(/^\s+/, "");
|
|
94
|
+
return { replyToMessageId: matched.id, cleanedContent };
|
|
95
|
+
}
|
|
96
|
+
function resolveQuoteTarget(quoteText, candidates) {
|
|
97
|
+
const trimmed = quoteText.trim();
|
|
98
|
+
if (!trimmed)
|
|
99
|
+
return undefined;
|
|
100
|
+
const authorBody = trimmed.match(AUTHOR_BODY_RE);
|
|
101
|
+
if (authorBody) {
|
|
102
|
+
return findBestMatch(authorBody[2], candidates, authorBody[1]);
|
|
103
|
+
}
|
|
104
|
+
return findMostRecentByAuthor(trimmed, candidates) ?? findBestMatch(trimmed, candidates);
|
|
105
|
+
}
|
|
106
|
+
function findBestMatch(quoteText, candidates, authorName, options = {}) {
|
|
107
|
+
const target = normalizeForMatch(quoteText);
|
|
108
|
+
if (!target)
|
|
109
|
+
return undefined;
|
|
110
|
+
const ordered = [...candidates].reverse();
|
|
111
|
+
const authorMatches = authorName
|
|
112
|
+
? ordered.filter((candidate) => candidateMatchesAuthor(candidate, authorName))
|
|
113
|
+
: [];
|
|
114
|
+
const pools = authorMatches.length ? [authorMatches, ordered] : [ordered];
|
|
115
|
+
for (const pool of pools) {
|
|
116
|
+
for (const candidate of pool) {
|
|
117
|
+
if (normalizeForMatch(candidate.content) === target)
|
|
118
|
+
return candidate;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (options.allowContainment !== false) {
|
|
122
|
+
for (const pool of pools) {
|
|
123
|
+
for (const candidate of pool) {
|
|
124
|
+
const candNorm = normalizeForMatch(candidate.content);
|
|
125
|
+
if (!candNorm)
|
|
126
|
+
continue;
|
|
127
|
+
if (candNorm.includes(target) || target.includes(candNorm))
|
|
128
|
+
return candidate;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (options.allowJaccard !== false) {
|
|
133
|
+
for (const pool of pools) {
|
|
134
|
+
let best = undefined;
|
|
135
|
+
let bestScore = JACCARD_THRESHOLD;
|
|
136
|
+
for (const candidate of pool) {
|
|
137
|
+
const score = jaccard(target, normalizeForMatch(candidate.content));
|
|
138
|
+
if (score > bestScore) {
|
|
139
|
+
bestScore = score;
|
|
140
|
+
best = candidate;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (best)
|
|
144
|
+
return best;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
export function normalizeForMatch(input) {
|
|
150
|
+
return input
|
|
151
|
+
.toLowerCase()
|
|
152
|
+
.replace(/\p{Extended_Pictographic}/gu, " ")
|
|
153
|
+
.replace(/[^\p{L}\p{N}\s]/gu, " ")
|
|
154
|
+
.replace(/\s+/g, " ")
|
|
155
|
+
.trim();
|
|
156
|
+
}
|
|
157
|
+
function matchTokenCount(input) {
|
|
158
|
+
return normalizeForMatch(input).split(" ").filter(Boolean).length;
|
|
159
|
+
}
|
|
160
|
+
function jaccard(a, b) {
|
|
161
|
+
const setA = new Set(a.split(" ").filter(Boolean));
|
|
162
|
+
const setB = new Set(b.split(" ").filter(Boolean));
|
|
163
|
+
if (setA.size === 0 || setB.size === 0)
|
|
164
|
+
return 0;
|
|
165
|
+
let intersection = 0;
|
|
166
|
+
for (const token of setA) {
|
|
167
|
+
if (setB.has(token))
|
|
168
|
+
intersection += 1;
|
|
169
|
+
}
|
|
170
|
+
const union = setA.size + setB.size - intersection;
|
|
171
|
+
return intersection / union;
|
|
172
|
+
}
|
|
173
|
+
function findMostRecentByAuthor(authorName, candidates) {
|
|
174
|
+
const normalized = normalizeForMatch(authorName);
|
|
175
|
+
if (!normalized)
|
|
176
|
+
return undefined;
|
|
177
|
+
return [...candidates]
|
|
178
|
+
.reverse()
|
|
179
|
+
.find((candidate) => candidateMatchesAuthor(candidate, authorName));
|
|
180
|
+
}
|
|
181
|
+
function candidateMatchesAuthor(candidate, authorName) {
|
|
182
|
+
const target = normalizeForMatch(authorName);
|
|
183
|
+
if (!target)
|
|
184
|
+
return false;
|
|
185
|
+
return [candidate.displayName, candidate.name]
|
|
186
|
+
.map(normalizeForMatch)
|
|
187
|
+
.some((candidateName) => candidateName === target);
|
|
188
|
+
}
|
|
189
|
+
function trimBlankLines(lines) {
|
|
190
|
+
let start = 0;
|
|
191
|
+
let end = lines.length;
|
|
192
|
+
while (start < end && lines[start].trim() === "")
|
|
193
|
+
start += 1;
|
|
194
|
+
while (end > start && lines[end - 1].trim() === "")
|
|
195
|
+
end -= 1;
|
|
196
|
+
return lines.slice(start, end);
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=replyQuote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replyQuote.js","sourceRoot":"","sources":["../../src/orchestration/replyQuote.ts"],"names":[],"mappings":"AAOA,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACjD,MAAM,yBAAyB,GAAG,4CAA4C,CAAC;AAC/E,MAAM,cAAc,GAAG,mCAAmC,CAAC;AAC3D,MAAM,sBAAsB,GAAG,mCAAmC,CAAC;AACnE,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAM9B,MAAM,UAAU,iBAAiB,CAC/B,OAA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