refactor: share reaction schemas and notes
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import { Type } from "@sinclair/typebox";
|
||||
|
||||
import { createReactionSchema } from "./reaction-schema.js";
|
||||
|
||||
export const DiscordToolSchema = Type.Union([
|
||||
Type.Object({
|
||||
action: Type.Literal("react"),
|
||||
channelId: Type.String(),
|
||||
messageId: Type.String(),
|
||||
emoji: Type.String(),
|
||||
remove: Type.Optional(Type.Boolean()),
|
||||
createReactionSchema({
|
||||
ids: {
|
||||
channelId: Type.String(),
|
||||
messageId: Type.String(),
|
||||
},
|
||||
includeRemove: true,
|
||||
}),
|
||||
Type.Object({
|
||||
action: Type.Literal("reactions"),
|
||||
|
||||
24
src/agents/tools/reaction-schema.ts
Normal file
24
src/agents/tools/reaction-schema.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { type TSchema, Type } from "@sinclair/typebox";
|
||||
|
||||
type ReactionSchemaOptions = {
|
||||
action?: string;
|
||||
ids: Record<string, TSchema>;
|
||||
emoji?: TSchema;
|
||||
includeRemove?: boolean;
|
||||
extras?: Record<string, TSchema>;
|
||||
};
|
||||
|
||||
export function createReactionSchema(options: ReactionSchemaOptions) {
|
||||
const schema: Record<string, TSchema> = {
|
||||
action: Type.Literal(options.action ?? "react"),
|
||||
...options.ids,
|
||||
emoji: options.emoji ?? Type.String(),
|
||||
};
|
||||
if (options.includeRemove) {
|
||||
schema.remove = Type.Optional(Type.Boolean());
|
||||
}
|
||||
if (options.extras) {
|
||||
Object.assign(schema, options.extras);
|
||||
}
|
||||
return Type.Object(schema);
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
import { Type } from "@sinclair/typebox";
|
||||
|
||||
import { createReactionSchema } from "./reaction-schema.js";
|
||||
|
||||
export const SlackToolSchema = Type.Union([
|
||||
Type.Object({
|
||||
action: Type.Literal("react"),
|
||||
channelId: Type.String(),
|
||||
messageId: Type.String(),
|
||||
emoji: Type.String(),
|
||||
remove: Type.Optional(Type.Boolean()),
|
||||
createReactionSchema({
|
||||
ids: {
|
||||
channelId: Type.String(),
|
||||
messageId: Type.String(),
|
||||
},
|
||||
includeRemove: true,
|
||||
}),
|
||||
Type.Object({
|
||||
action: Type.Literal("reactions"),
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { Type } from "@sinclair/typebox";
|
||||
|
||||
import { createReactionSchema } from "./reaction-schema.js";
|
||||
|
||||
export const TelegramToolSchema = Type.Union([
|
||||
Type.Object({
|
||||
action: Type.Literal("react"),
|
||||
chatId: Type.Union([Type.String(), Type.Number()]),
|
||||
messageId: Type.Union([Type.String(), Type.Number()]),
|
||||
emoji: Type.String(),
|
||||
remove: Type.Optional(Type.Boolean()),
|
||||
createReactionSchema({
|
||||
ids: {
|
||||
chatId: Type.Union([Type.String(), Type.Number()]),
|
||||
messageId: Type.Union([Type.String(), Type.Number()]),
|
||||
},
|
||||
includeRemove: true,
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import { Type } from "@sinclair/typebox";
|
||||
|
||||
import { createReactionSchema } from "./reaction-schema.js";
|
||||
|
||||
export const WhatsAppToolSchema = Type.Union([
|
||||
Type.Object({
|
||||
action: Type.Literal("react"),
|
||||
chatJid: Type.String(),
|
||||
messageId: Type.String(),
|
||||
emoji: Type.String(),
|
||||
remove: Type.Optional(Type.Boolean()),
|
||||
participant: Type.Optional(Type.String()),
|
||||
accountId: Type.Optional(Type.String()),
|
||||
fromMe: Type.Optional(Type.Boolean()),
|
||||
createReactionSchema({
|
||||
ids: {
|
||||
chatJid: Type.String(),
|
||||
messageId: Type.String(),
|
||||
},
|
||||
includeRemove: true,
|
||||
extras: {
|
||||
participant: Type.Optional(Type.String()),
|
||||
accountId: Type.Optional(Type.String()),
|
||||
fromMe: Type.Optional(Type.Boolean()),
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user