mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 23:51:55 +00:00
fixed
This commit is contained in:
+16
-7
@@ -1,4 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { z, ZodLiteral } from "zod";
|
||||
import quickChatData from "../../resources/QuickChat.json" with { type: "json" };
|
||||
import {
|
||||
AllPlayers,
|
||||
Difficulty,
|
||||
@@ -271,15 +272,23 @@ export const MoveWarshipIntentSchema = BaseIntentSchema.extend({
|
||||
tile: z.number(),
|
||||
});
|
||||
|
||||
const allowedQuickChatKeys = Object.entries(quickChatData).flatMap(
|
||||
([category, entries]) => entries.map((entry) => `${category}.${entry.key}`),
|
||||
);
|
||||
|
||||
const literals = allowedQuickChatKeys.map((key) => z.literal(key));
|
||||
|
||||
// ✅ より型安全なアサーション
|
||||
export const QuickChatIntentSchema = BaseIntentSchema.extend({
|
||||
type: z.literal("quick_chat"),
|
||||
recipient: ID,
|
||||
quickChatKey: z
|
||||
.string()
|
||||
.regex(/^(help|attack|defend|greet|misc)\.[a-zA-Z0-9_]+$/)
|
||||
.refine((val) => val.split(".")[1]?.length <= 50, {
|
||||
message: "The key name (after the dot) must be 50 characters or less.",
|
||||
}),
|
||||
quickChatKey: z.union(
|
||||
literals as [
|
||||
ZodLiteral<string>,
|
||||
ZodLiteral<string>,
|
||||
...ZodLiteral<string>[],
|
||||
],
|
||||
),
|
||||
variables: z.record(z.string()).optional(),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user