validators.ts•3.14 kB
import { z } from 'zod';
import { blocksArraySchema } from './block-validators.js';
// Common validators
export const channelIdSchema = z.string().regex(/^(C|G|D)[A-Z0-9]+$/, 'Invalid conversation ID format');
export const userIdSchema = z.string().regex(/^U[A-Z0-9]+$/, 'Invalid user ID format');
export const timestampSchema = z.string().regex(/^\d+\.\d+$/, 'Invalid timestamp format');
export const emojiSchema = z.string().min(1).max(100);
// Channel tool schemas
export const listChannelsSchema = z.object({
types: z.string().optional().default('public_channel,private_channel'),
exclude_archived: z.boolean().optional().default(true),
limit: z.number().min(1).max(1000).optional().default(100),
cursor: z.string().optional(),
});
export const getChannelInfoSchema = z.object({
channel: channelIdSchema,
});
export const createChannelSchema = z.object({
name: z.string().min(1).max(80).regex(/^[a-z0-9-_]+$/, 'Channel name must be lowercase with hyphens or underscores'),
is_private: z.boolean().optional().default(false),
});
export const archiveChannelSchema = z.object({
channel: channelIdSchema,
});
// User tool schemas
export const listUsersSchema = z.object({
limit: z.number().min(1).max(1000).optional().default(100),
cursor: z.string().optional(),
});
export const getUserInfoSchema = z.object({
user: userIdSchema,
});
export const inviteToChannelSchema = z.object({
channel: channelIdSchema,
users: z.array(userIdSchema).min(1),
});
// Message tool schemas
export const sendMessageSchema = z.object({
channel: channelIdSchema,
text: z.string().min(1),
thread_ts: timestampSchema.optional(),
});
export const updateMessageSchema = z.object({
channel: channelIdSchema,
ts: timestampSchema,
text: z.string().min(1),
});
export const deleteMessageSchema = z.object({
channel: channelIdSchema,
ts: timestampSchema,
});
export const getChannelHistorySchema = z.object({
channel: channelIdSchema,
limit: z.number().min(1).max(1000).optional().default(100),
oldest: timestampSchema.optional(),
latest: timestampSchema.optional(),
cursor: z.string().optional(),
});
export const searchMessagesSchema = z.object({
query: z.string().min(1),
count: z.number().min(1).max(100).optional().default(20),
sort: z.enum(['score', 'timestamp']).optional().default('score'),
});
export const sendFormattedMessageSchema = z.object({
channel: channelIdSchema,
text: z.string().min(1),
blocks: blocksArraySchema,
thread_ts: timestampSchema.optional(),
});
// File tool schemas
export const uploadFileSchema = z.object({
channels: z.array(channelIdSchema).min(1),
content: z.string().min(1),
filename: z.string().min(1),
title: z.string().optional(),
initial_comment: z.string().optional(),
});
// Reaction tool schemas
export const addReactionSchema = z.object({
channel: channelIdSchema,
timestamp: timestampSchema,
name: emojiSchema,
});
export const removeReactionSchema = z.object({
channel: channelIdSchema,
timestamp: timestampSchema,
name: emojiSchema,
});
// Workspace tool schemas
export const getTeamInfoSchema = z.object({});