An npc-dialogues document can be marked testing, which keeps it off the player site while letting the superuser tier walk it live. Enforced in one module, lib/npc-dialogue/visibility.ts: the offer skips the conversation, its new-message badge never appears, and every node lookup re-checks visibility. Those lookups now name their conversation. The client sends dialogue.id and the server verifies it belongs to the NPC and is visible to the reader, so a player cannot read a testing conversation's nodes by guessing an id. The old lookup took limit: 1 on the NPC's conversations with no ordering, which with a testing conversation present could read the wrong document and silently skip an effect. Tester tier is system:admin-access, not every author: an officer who can edit conversations still cannot reach a testing one on the player site. Only an explicit true hides a conversation, so rows written before the flag stay live.
226 lines
7.3 KiB
TypeScript
226 lines
7.3 KiB
TypeScript
import { CollectionConfig } from "payload";
|
|
import { requirePermission } from "@/utils/access-control/hasPermission";
|
|
import { CONDITION_OPS, NUMERIC_CONDITION_OPS } from "@/lib/npc-dialogue/dialogue";
|
|
import { cleanPromptText, MAX_VOICE_CHARS } from "@/lib/npc-dialogue/normalize";
|
|
|
|
export const NpcDialogues: CollectionConfig = {
|
|
slug: "npc-dialogues",
|
|
admin: {
|
|
group: "Game",
|
|
useAsTitle: "name",
|
|
listSearchableFields: ["name"],
|
|
defaultColumns: ["name", "npc", "priority", "testing"],
|
|
pagination: { defaultLimit: 50 },
|
|
},
|
|
access: {
|
|
read: requirePermission("npc-dialogues:read"),
|
|
create: requirePermission("npc-dialogues:create"),
|
|
update: requirePermission("npc-dialogues:update"),
|
|
delete: requirePermission("npc-dialogues:delete"),
|
|
},
|
|
fields: [
|
|
{
|
|
name: "name",
|
|
type: "text",
|
|
required: true,
|
|
admin: {
|
|
description: "A short label for this conversation (e.g. 'Merchant greeting').",
|
|
},
|
|
},
|
|
{
|
|
name: "npc",
|
|
type: "relationship",
|
|
relationTo: "game-npcs",
|
|
required: true,
|
|
hasMany: false,
|
|
admin: {
|
|
description: "The contact this conversation belongs to.",
|
|
},
|
|
filterOptions: {
|
|
canMessage: { equals: true },
|
|
},
|
|
},
|
|
{
|
|
name: "priority",
|
|
type: "number",
|
|
defaultValue: 0,
|
|
admin: {
|
|
description:
|
|
"When a contact has several conversations, the highest-priority one whose entry gate passes is the one offered. Ties break by oldest first.",
|
|
},
|
|
},
|
|
{
|
|
name: "testing",
|
|
type: "checkbox",
|
|
defaultValue: false,
|
|
label: "Testing: superusers only",
|
|
admin: {
|
|
description:
|
|
"Walk this conversation on the live site without releasing it. Only the superuser tier is offered it: players never see it or its new-message badge, and it cannot be resolved by guessing its id. Untick to publish.",
|
|
},
|
|
},
|
|
{
|
|
name: "entryGate",
|
|
type: "group",
|
|
admin: {
|
|
description:
|
|
"Only offer this conversation to players whose flags pass this condition. Leave the key empty to always offer it (ungated conversations are the fallback).",
|
|
},
|
|
fields: [
|
|
{
|
|
name: "key",
|
|
type: "text",
|
|
admin: {
|
|
description:
|
|
"player-flags key checked for the reading player. Player-specific flag takes priority; falls back to global. Missing = false / 0.",
|
|
},
|
|
},
|
|
{
|
|
name: "op",
|
|
type: "select",
|
|
defaultValue: "is_true",
|
|
options: CONDITION_OPS,
|
|
admin: {
|
|
description: "Comparison applied to the flag's effective value.",
|
|
},
|
|
},
|
|
{
|
|
name: "amount",
|
|
type: "number",
|
|
admin: {
|
|
condition: (_data, blockData) =>
|
|
NUMERIC_CONDITION_OPS.includes(String(blockData?.op) as never),
|
|
description: "Right-hand side for the numeric comparisons.",
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
type: "tabs",
|
|
tabs: [
|
|
{
|
|
label: "Flow Editor",
|
|
description:
|
|
"Build the conversation: dialogue lines, branching choices, and trigger events. Mark one node as the start.",
|
|
fields: [
|
|
{
|
|
name: "flowData",
|
|
type: "json",
|
|
required: true,
|
|
defaultValue: () => ({
|
|
nodes: [],
|
|
edges: [],
|
|
}),
|
|
admin: {
|
|
components: {
|
|
Field: "@/components/admin/npc-dialogue/NpcDialogueEditor",
|
|
},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
label: "AI Drafting",
|
|
description:
|
|
"How the drafting tools should sound for this conversation. The preview shows the assembled instruction for a whole-conversation draft.",
|
|
fields: [
|
|
{
|
|
name: "voiceOverride",
|
|
type: "textarea",
|
|
hooks: {
|
|
// The same cleaning the global voice gets: this text outranks it,
|
|
// so leaving dashes and unbounded length here would make the most
|
|
// specific instruction the least constrained one.
|
|
beforeValidate: [({ value }) => cleanPromptText(value, MAX_VOICE_CHARS)],
|
|
},
|
|
admin: {
|
|
description:
|
|
"Replaces the global voice for this conversation only. Leave blank to use the global setting, or the built-in voice if that is blank too. Write about register and personality only: structure and field rules are fixed in code.",
|
|
},
|
|
},
|
|
{
|
|
name: "promptPreview",
|
|
type: "ui",
|
|
admin: {
|
|
components: {
|
|
Field: "@/components/admin/npc-dialogue/PromptPreview#DialoguePromptPreview",
|
|
},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: "generation",
|
|
type: "group",
|
|
label: "AI Draft Provenance",
|
|
admin: {
|
|
readOnly: true,
|
|
description:
|
|
"Which model drafted this conversation and from what brief. Written when the document is saved, so it describes the draft that was accepted, not every attempt. Editing the flow by hand afterwards does not clear it.",
|
|
},
|
|
fields: [
|
|
{
|
|
name: "model",
|
|
type: "text",
|
|
admin: { description: "Served model id that produced the draft.", readOnly: true },
|
|
},
|
|
{
|
|
name: "promptVersion",
|
|
type: "text",
|
|
admin: { description: "Prompt contract version, so an old draft is comparable.", readOnly: true },
|
|
},
|
|
{
|
|
name: "promptSource",
|
|
type: "select",
|
|
options: [
|
|
{ label: "Built-in voice", value: "builtin" },
|
|
{ label: "Global setting", value: "global" },
|
|
{ label: "This dialogue", value: "dialogue" },
|
|
],
|
|
admin: {
|
|
description: "Which voice shaped the prompt: the built-in default, the global setting, or this dialogue's override.",
|
|
readOnly: true,
|
|
},
|
|
},
|
|
{
|
|
name: "connectionLabel",
|
|
type: "text",
|
|
admin: {
|
|
description:
|
|
"The admin connection that served the model. Empty means the Unsloth environment defaults.",
|
|
readOnly: true,
|
|
},
|
|
},
|
|
{
|
|
name: "promptRevision",
|
|
type: "number",
|
|
admin: {
|
|
description:
|
|
"Revision of the prompt settings in force when this draft was made. Empty for the built-in voice, which has no settings revision.",
|
|
readOnly: true,
|
|
},
|
|
},
|
|
{
|
|
name: "attempts",
|
|
type: "number",
|
|
admin: { description: "1 when the first output validated, 2 when it was retried.", readOnly: true },
|
|
},
|
|
{
|
|
name: "generatedAt",
|
|
type: "date",
|
|
admin: { description: "When the draft was generated.", readOnly: true },
|
|
},
|
|
{
|
|
name: "brief",
|
|
type: "json",
|
|
admin: {
|
|
description: "The form brief the author filled in when drafting.",
|
|
readOnly: true,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|