From 0bef499aace1ca162d318e6f1bb3eb1b434b4337 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Mon, 12 Oct 2026 15:23:55 +0900 Subject: [PATCH] Enhance ChatEvent with JSON schema and fromJSON method Added JSON schema validation and deserialization to ChatEvent. --- index.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/index.ts b/index.ts index 94dfde0..bbba51d 100644 --- a/index.ts +++ b/index.ts @@ -16,13 +16,15 @@ export class ChatEvent { public content: string, ) {} - static async fromContext(context: InstancePluginContext) { - return new ChatEvent(context.instance, context.action, context.content); - } -} + static jsonSchema = Type.Object({ + 'instance': Type.Any(), + 'action': Type.String(), + 'content': Type.String(), + }); -export default async function (context: InstancePluginContext) { - await ChatEvent.fromContext(context); + static fromJSON(json: Static) { + return new this(json.instance, json.action, json.content); + } } declare module '@clusterio/lib' {