(value: unknown)
| 6 | !value || typeof value !== 'object' || Array.isArray(value) ? null : (value as T) |
| 7 | |
| 8 | export const asCommandDispatch = (value: unknown): CommandDispatchResponse | null => { |
| 9 | const o = asRpcResult(value) |
| 10 | |
| 11 | if (!o || typeof o.type !== 'string') { |
| 12 | return null |
| 13 | } |
| 14 | |
| 15 | const t = o.type |
| 16 | |
| 17 | if (t === 'exec' || t === 'plugin') { |
| 18 | return { type: t, output: typeof o.output === 'string' ? o.output : undefined } |
| 19 | } |
| 20 | |
| 21 | if (t === 'alias' && typeof o.target === 'string') { |
| 22 | return { type: 'alias', target: o.target } |
| 23 | } |
| 24 | |
| 25 | if (t === 'skill' && typeof o.name === 'string') { |
| 26 | return { type: 'skill', name: o.name, message: typeof o.message === 'string' ? o.message : undefined } |
| 27 | } |
| 28 | |
| 29 | if (t === 'send' && typeof o.message === 'string') { |
| 30 | return { |
| 31 | type: 'send', |
| 32 | message: o.message, |
| 33 | notice: typeof o.notice === 'string' ? o.notice : undefined |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | if (t === 'prefill' && typeof o.message === 'string') { |
| 38 | return { |
| 39 | type: 'prefill', |
| 40 | message: o.message, |
| 41 | notice: typeof o.notice === 'string' ? o.notice : undefined |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | return null |
| 46 | } |
| 47 | |
| 48 | export const rpcErrorMessage = (err: unknown) => |
| 49 | err instanceof Error && err.message ? err.message : typeof err === 'string' && err.trim() ? err : 'request failed' |
no test coverage detected