Enhance ChatEvent with JSON schema and fromJSON method

Added JSON schema validation and deserialization to ChatEvent.
This commit is contained in:
phidias authored and GitHub committed 2026-10-12 15:23:55 +09:00
1 parent 6ad2d7ac5e
commit 0bef499aac
1 file changed
+8 -6
+8 -6
View File
@@ -16,13 +16,15 @@ export class ChatEvent {
public content: string, public content: string,
) {} ) {}
static async fromContext(context: InstancePluginContext) { static jsonSchema = Type.Object({
return new ChatEvent(context.instance, context.action, context.content); 'instance': Type.Any(),
} 'action': Type.String(),
} 'content': Type.String(),
});
export default async function (context: InstancePluginContext) { static fromJSON(json: Static<typeof ChatEvent.jsonSchema>) {
await ChatEvent.fromContext(context); return new this(json.instance, json.action, json.content);
}
} }
declare module '@clusterio/lib' { declare module '@clusterio/lib' {