(
params: Record<string, unknown>,
key: string,
options: StringParamOptions = {},
)
| 143 | options?: StringParamOptions, |
| 144 | ): string[] | undefined; |
| 145 | export function readStringArrayParam( |
| 146 | params: Record<string, unknown>, |
| 147 | key: string, |
| 148 | options: StringParamOptions = {}, |
| 149 | ) { |
| 150 | const { required = false, label = key } = options; |
| 151 | const raw = params[key]; |
| 152 | if (Array.isArray(raw)) { |
| 153 | const values = raw |
| 154 | .filter((entry) => typeof entry === "string") |
| 155 | .map((entry) => entry.trim()) |
| 156 | .filter(Boolean); |
| 157 | if (values.length === 0) { |
| 158 | if (required) { |
| 159 | throw new ToolInputError(`${label} required`); |
| 160 | } |
| 161 | return undefined; |
| 162 | } |
| 163 | return values; |
| 164 | } |
| 165 | if (typeof raw === "string") { |
| 166 | const value = raw.trim(); |
| 167 | if (!value) { |
| 168 | if (required) { |
| 169 | throw new ToolInputError(`${label} required`); |
| 170 | } |
| 171 | return undefined; |
| 172 | } |
| 173 | return [value]; |
| 174 | } |
| 175 | if (required) { |
| 176 | throw new ToolInputError(`${label} required`); |
| 177 | } |
| 178 | return undefined; |
| 179 | } |
| 180 | |
| 181 | export type ReactionParams = { |
| 182 | emoji: string; |
no test coverage detected